Round-robin tournament schedule: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) (→{{header|Perl}}: added alternate version) |
Catskill549 (talk | contribs) (added AWK) |
||
Line 11: | Line 11: | ||
<br> |
<br> |
||
=={{header|AWK}}== |
|||
<lang AWK> |
|||
# syntax: GAWK -f ROUND-ROBIN_TOURNAMENT_SCHEDULE.AWK |
|||
BEGIN { |
|||
main(1) |
|||
main(2) |
|||
main(5,"The Bizzaros") |
|||
main(12) |
|||
exit(0) |
|||
} |
|||
function main(n,description, arr,i,j,leng,tmp) { |
|||
if (n < 2) { |
|||
printf("\n%d is too few participants\n",n) |
|||
return |
|||
} |
|||
printf("\n%d players %s\n",n,description) |
|||
for (i=1; i<=n; i++) { |
|||
arr[i] = i |
|||
} |
|||
if (n % 2 == 1) { |
|||
arr[++n] = 0 # a "bye" |
|||
} |
|||
leng = length(n-1) |
|||
for (i=1; i<n; i++) { |
|||
printf("\nround %*d:",leng,i) |
|||
for (j=1; j<=n/2; j++) { |
|||
printf("%4s",arr[j]==0?"bye":arr[j]) |
|||
} |
|||
printf("\n%*s",leng+7,"") |
|||
for (j=n; j>n/2; j--) { |
|||
printf("%4s",arr[j]==0?"bye":arr[j]) |
|||
} |
|||
printf("\n") |
|||
tmp = arr[n] |
|||
for (j=n; j>2; j--) { |
|||
arr[j] = arr[j-1] |
|||
} |
|||
arr[2] = tmp |
|||
} |
|||
} |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
1 is too few participants |
|||
2 players |
|||
round 1: 1 |
|||
2 |
|||
5 players The Bizzaros |
|||
round 1: 1 2 3 |
|||
bye 5 4 |
|||
round 2: 1 bye 2 |
|||
5 4 3 |
|||
round 3: 1 5 bye |
|||
4 3 2 |
|||
round 4: 1 4 5 |
|||
3 2 bye |
|||
round 5: 1 3 4 |
|||
2 bye 5 |
|||
12 players |
|||
round 1: 1 2 3 4 5 6 |
|||
12 11 10 9 8 7 |
|||
round 2: 1 12 2 3 4 5 |
|||
11 10 9 8 7 6 |
|||
round 3: 1 11 12 2 3 4 |
|||
10 9 8 7 6 5 |
|||
round 4: 1 10 11 12 2 3 |
|||
9 8 7 6 5 4 |
|||
round 5: 1 9 10 11 12 2 |
|||
8 7 6 5 4 3 |
|||
round 6: 1 8 9 10 11 12 |
|||
7 6 5 4 3 2 |
|||
round 7: 1 7 8 9 10 11 |
|||
6 5 4 3 2 12 |
|||
round 8: 1 6 7 8 9 10 |
|||
5 4 3 2 12 11 |
|||
round 9: 1 5 6 7 8 9 |
|||
4 3 2 12 11 10 |
|||
round 10: 1 4 5 6 7 8 |
|||
3 2 12 11 10 9 |
|||
round 11: 1 3 4 5 6 7 |
|||
2 12 11 10 9 8 |
|||
</pre> |
|||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
<lang freebasic>function nob( n as uinteger, i as uinteger, bye as boolean ) as string |
<lang freebasic>function nob( n as uinteger, i as uinteger, bye as boolean ) as string |