Round-robin tournament schedule: Difference between revisions

No edit summary
Line 10:
:* '''[[wp:Round-robin tournament|Wikipedia - Round-robin tournament]]'''
<br>
 
=={{header|Julia}}==
<lang julia>""" https://rosettacode.org/mw/index.php?title=Round-robin_tournament_schedule """
 
function schurig(N, verbose = true)
""" Taken from https://en.wikipedia.org/wiki/Round-robin_tournament
#Original_construction_of_pairing_tables_by_Richard_Schurig_(1886) """
nrows = isodd(N) ? N : N - 1
ncols = (N + 1) ÷ 2
players = mod1.(reshape(collect(1:nrows*ncols), ncols, nrows)', nrows)
opponents = zero(players)
table = [(0, 0) for _ in 1:nrows, _ in 1:ncols]
for i in 1:nrows
oldrow = i == nrows ? 1 : i + 1
verbose && print("\n", rpad("Round $i:", 10))
for j in 1:ncols
oldcol = ncols - j + 1
opponents[i, j] = players[oldrow, oldcol]
j == 1 && (opponents[i, j] = iseven(N) ? N : 0)
table[i, j] = (sort([players[i, j], opponents[i, j]])...,)
players[i, j] > opponents[i, j] && (table[i, j] == reverse(table[i, j]))
if verbose
s1, s2 = string.(table[i, j])
print(rpad("($(s1 == "0" ? "Bye" : s1) - $s2)", 10))
end
end
end
return table
end
 
print("Schurig table for round robin with 12 players:")
schurig(12)
print("\n\nSchurig table for round robin with 7 players:")
schurig(7)
</lang>{{out}}
<pre>
Schurig table for round robin with 12 players:
Round 1: (1 - 12) (2 - 11) (3 - 10) (4 - 9) (5 - 8) (6 - 7)
Round 2: (7 - 12) (6 - 8) (5 - 9) (4 - 10) (3 - 11) (1 - 2)
Round 3: (2 - 12) (1 - 3) (4 - 11) (5 - 10) (6 - 9) (7 - 8)
Round 4: (8 - 12) (7 - 9) (6 - 10) (5 - 11) (1 - 4) (2 - 3)
Round 5: (3 - 12) (2 - 4) (1 - 5) (6 - 11) (7 - 10) (8 - 9)
Round 6: (9 - 12) (8 - 10) (7 - 11) (1 - 6) (2 - 5) (3 - 4)
Round 7: (4 - 12) (3 - 5) (2 - 6) (1 - 7) (8 - 11) (9 - 10)
Round 8: (10 - 12) (9 - 11) (1 - 8) (2 - 7) (3 - 6) (4 - 5)
Round 9: (5 - 12) (4 - 6) (3 - 7) (2 - 8) (1 - 9) (10 - 11)
Round 10: (11 - 12) (1 - 10) (2 - 9) (3 - 8) (4 - 7) (5 - 6)
Round 11: (6 - 12) (5 - 7) (4 - 8) (3 - 9) (2 - 10) (1 - 11)
 
Schurig table for round robin with 7 players:
Round 1: (Bye - 1) (2 - 7) (3 - 6) (4 - 5)
Round 2: (Bye - 5) (4 - 6) (3 - 7) (1 - 2)
Round 3: (Bye - 2) (1 - 3) (4 - 7) (5 - 6)
Round 4: (Bye - 6) (5 - 7) (1 - 4) (2 - 3)
Round 5: (Bye - 3) (2 - 4) (1 - 5) (6 - 7)
Round 6: (Bye - 7) (1 - 6) (2 - 5) (3 - 4)
Round 7: (Bye - 4) (3 - 5) (2 - 6) (1 - 7)
</pre>
 
=={{header|Perl}}==
4,107

edits