Round-robin tournament schedule: Difference between revisions
Content added Content deleted
(→{{header|Wren}}: More pruning.) |
(add FreeBASIC) |
||
Line 10: | Line 10: | ||
:* '''[[wp:Round-robin tournament|Wikipedia - Round-robin tournament]]''' |
:* '''[[wp:Round-robin tournament|Wikipedia - Round-robin tournament]]''' |
||
<br> |
<br> |
||
=={{header|FreeBASIC}}== |
|||
<lang freebasic>function nob( n as uinteger, i as uinteger, bye as boolean ) as string |
|||
'helper function to allow byes to be printed intelligently |
|||
dim as string pad |
|||
if n > 9 then pad = " " else pad = "" |
|||
if n = i and bye then |
|||
return pad+"B" |
|||
else |
|||
if i<10 then return pad + str(i) else return str(i) |
|||
end if |
|||
end function |
|||
sub roundrob( byval n as uinteger ) |
|||
dim as boolean bye = false |
|||
if n mod 2 = 1 then 'if there is an odd number of competitors |
|||
bye = 1 'make note of this fact |
|||
n += 1 'and treat the tournament as having one more competitor |
|||
end if |
|||
dim as uinteger schd(1 to n), r, i, temp1, temp2 |
|||
for i = 1 to n |
|||
schd(i) =i 'initial population of the array with numbers 1-n |
|||
next i |
|||
for r = 1 to n-1 |
|||
print using "Round ##: ";r; |
|||
for i = 1 to n/2 'print the pairings according to the scheme |
|||
'1 2 3 4 |
|||
'5 6 7 8 |
|||
print using "(& - &) ";nob(n,schd(i),bye);nob(n,schd(i+n\2),bye); |
|||
next i |
|||
print |
|||
'now move positions 2-n around clockwise |
|||
temp1 = schd(n/2) 'need to track two temporary variables |
|||
temp2 = schd(n/2+1) |
|||
for i = n/2 to 3 step -1 'top row |
|||
schd(i) = schd(i-1) |
|||
next i |
|||
for i = n/2+1 to n-1 'bottom row |
|||
schd(i) = schd(i+1) |
|||
next i |
|||
schd(n) = temp1 'fill in the ones that "jumped" between rows |
|||
schd(2) = temp2 |
|||
next r |
|||
end sub |
|||
print "Twelve teams" |
|||
roundrob(12) |
|||
print "Nine teams with byes" |
|||
roundrob(9) |
|||
</lang> |
|||
{{out}}<pre> |
|||
Twelve teams |
|||
Round 1: ( 1 - 7) ( 2 - 8) ( 3 - 9) ( 4 - 10) ( 5 - 11) ( 6 - 12) |
|||
Round 2: ( 1 - 8) ( 7 - 9) ( 2 - 10) ( 3 - 11) ( 4 - 12) ( 5 - 6) |
|||
Round 3: ( 1 - 9) ( 8 - 10) ( 7 - 11) ( 2 - 12) ( 3 - 6) ( 4 - 5) |
|||
Round 4: ( 1 - 10) ( 9 - 11) ( 8 - 12) ( 7 - 6) ( 2 - 5) ( 3 - 4) |
|||
Round 5: ( 1 - 11) (10 - 12) ( 9 - 6) ( 8 - 5) ( 7 - 4) ( 2 - 3) |
|||
Round 6: ( 1 - 12) (11 - 6) (10 - 5) ( 9 - 4) ( 8 - 3) ( 7 - 2) |
|||
Round 7: ( 1 - 6) (12 - 5) (11 - 4) (10 - 3) ( 9 - 2) ( 8 - 7) |
|||
Round 8: ( 1 - 5) ( 6 - 4) (12 - 3) (11 - 2) (10 - 7) ( 9 - 8) |
|||
Round 9: ( 1 - 4) ( 5 - 3) ( 6 - 2) (12 - 7) (11 - 8) (10 - 9) |
|||
Round 10: ( 1 - 3) ( 4 - 2) ( 5 - 7) ( 6 - 8) (12 - 9) (11 - 10) |
|||
Round 11: ( 1 - 2) ( 3 - 7) ( 4 - 8) ( 5 - 9) ( 6 - 10) (12 - 11) |
|||
Nine teams with byes |
|||
Round 1: ( 1 - 6) ( 2 - 7) ( 3 - 8) ( 4 - 9) ( 5 - B) |
|||
Round 2: ( 1 - 7) ( 6 - 8) ( 2 - 9) ( 3 - B) ( 4 - 5) |
|||
Round 3: ( 1 - 8) ( 7 - 9) ( 6 - B) ( 2 - 5) ( 3 - 4) |
|||
Round 4: ( 1 - 9) ( 8 - B) ( 7 - 5) ( 6 - 4) ( 2 - 3) |
|||
Round 5: ( 1 - B) ( 9 - 5) ( 8 - 4) ( 7 - 3) ( 6 - 2) |
|||
Round 6: ( 1 - 5) ( B - 4) ( 9 - 3) ( 8 - 2) ( 7 - 6) |
|||
Round 7: ( 1 - 4) ( 5 - 3) ( B - 2) ( 9 - 6) ( 8 - 7) |
|||
Round 8: ( 1 - 3) ( 4 - 2) ( 5 - 6) ( B - 7) ( 9 - 8) |
|||
Round 9: ( 1 - 2) ( 3 - 6) ( 4 - 7) ( 5 - 8) ( B - 9) |
|||
</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |