Round-robin tournament schedule: Difference between revisions
m
syntax highlighting fixup automation
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 12:
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f ROUND-ROBIN_TOURNAMENT_SCHEDULE.AWK
BEGIN {
Line 51:
}
}
</syntaxhighlight>
{{out}}
<pre>
Line 114:
</pre>
=={{header|FreeBASIC}}==
<
'helper function to allow byes to be printed intelligently
dim as string pad
Line 161:
print "Nine teams with byes"
roundrob(9)
</syntaxhighlight>
{{out}}<pre>
Twelve teams
Line 189:
=={{header|Go}}==
{{trans|Wren}}
<
import "fmt"
Line 227:
fmt.Println("\n\nRound robin for 5 players (0 denotes a bye) :\n")
roundRobin(5)
}</
{{out}}
Line 235:
=={{header|Julia}}==
<
function schurig(N, verbose = true)
Line 266:
print("\n\nSchurig table for round robin with 7 players:")
schurig(7)
</
<pre>
Schurig table for round robin with 12 players:
Line 293:
=={{header|Perl}}==
===Even===
<
use strict; # https://rosettacode.org/wiki/Round-robin_tournament_schedule
Line 304:
@teams[0,$n-1,1..$n-2] = @teams;
printf 'Round %2d:' . '%4d vs %2d'x($n/2) . "\n", $_, @teams[ map { $_, $n-1-$_} 0..($n/2)-1 ];
}</
{{out}}
<pre>
Line 320:
</pre>
===Even and Odd===
<
use warnings;
use feature 'say';
Line 343:
say join '', round_robin 12;
say '';
say join '', map { s/0 vs /Bye: /r } round_robin 7;</
{{out}}
<pre>Round 1: 1 vs 12 2 vs 11 3 vs 10 4 vs 9 5 vs 8 6 vs 7
Line 367:
=={{header|Phix}}==
Based on the circle with rotor diagrams on the wikipedia page, and implements home/away.
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
Line 426:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</
{{out}}
<pre>
Line 449:
While I "optimised away" the need for a physical rotate, obviously not because I was concerned with performance but more in the hope of creating shorter and more elegant code, in the end it made little difference.
Should it be more to your taste, you can remove "l" and replace the inner loop above with:
<!--<
<span style="color: #004080;">sequence</span> <span style="color: #000000;">circle</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">rownd</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">n</span> <span style="color: #008080;">do</span> <span style="color: #000080;font-style:italic;">-- (since "round" is a bultin)</span>
Line 465:
<span style="color: #000000;">circle</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">circle</span><span style="color: #0000FF;">[</span><span style="color: #000000;">2</span><span style="color: #0000FF;">..$]&</span><span style="color: #000000;">circle</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #000080;font-style:italic;">-- (physically rotate it)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</
=={{header|Picat}}==
===Constraint modelling===
<
main =>
Line 530:
nl
end,
nl.</
{{out}}
Line 555:
* 7 vs 12 must be played in the last round
<
nolog,
N = 12,
Line 563:
[7,12,N-1]],
tournament_cp(N, NumRounds,NumPairs,Extras,X,Bye),
print_tournament(X,NumRounds,NumPairs,Bye).</
{{out}}
Line 585:
Here the cp solver is used since it's faster than the sat solver for generating all solutions.
<
main =>
Line 591:
Count = count_all(tournament_cp(N, _NumRounds,_NumPairs,_Extras,_X,_Bye)),
println(N=Count)
end.</
{{out}}
Line 603:
=={{header|Raku}}==
<syntaxhighlight lang="raku"
my $half = +@players div 2;
my $round = 0;
Line 611:
@players[1..*].=rotate(-1);
last if [<] @players;
}</
{{out}}
<pre>Round 1: ( 1 vs 12) ( 2 vs 11) ( 3 vs 10) ( 4 vs 9 ) ( 5 vs 8 ) ( 6 vs 7 )
Line 626:
=={{header|Ruby}}==
<
rotating_players = (2..n).map(&:to_s) #player 1 to be added later
rotating_players << "bye" if n.odd?
Line 642:
puts
end
</syntaxhighlight>
{{out}}
<pre>Round 1
Line 691:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<
var rotate = Fn.new { |lst|
Line 717:
roundRobin.call(12)
System.print("\n\nRound robin for 5 players (0 denotes a bye) :\n")
roundRobin.call(5)</
{{out}}
Line 746:
=={{header|XPL0}}==
<
int I, Player(N+1), Round, Temp;
[for I:= 1 to N do Player(I):= I;
Line 762:
Player(2):= Temp;
];
]</
{{out}}
|