Round-robin tournament schedule: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 12:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f ROUND-ROBIN_TOURNAMENT_SCHEDULE.AWK
BEGIN {
Line 51:
}
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 114:
</pre>
=={{header|FreeBASIC}}==
<langsyntaxhighlight 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
Line 161:
print "Nine teams with byes"
roundrob(9)
</syntaxhighlight>
</lang>
{{out}}<pre>
Twelve teams
Line 189:
=={{header|Go}}==
{{trans|Wren}}
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 227:
fmt.Println("\n\nRound robin for 5 players (0 denotes a bye) :\n")
roundRobin(5)
}</langsyntaxhighlight>
 
{{out}}
Line 235:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">""" https://rosettacode.org/mw/index.php?title=Round-robin_tournament_schedule """
 
function schurig(N, verbose = true)
Line 266:
print("\n\nSchurig table for round robin with 7 players:")
schurig(7)
</langsyntaxhighlight>{{out}}
<pre>
Schurig table for round robin with 12 players:
Line 293:
=={{header|Perl}}==
===Even===
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
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 ];
}</langsyntaxhighlight>
{{out}}
<pre>
Line 320:
</pre>
===Even and Odd===
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 343:
say join '', round_robin 12;
say '';
say join '', map { s/0 vs /Bye: /r } round_robin 7;</langsyntaxhighlight>
{{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.
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<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>
<!--</langsyntaxhighlight>-->
{{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:
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<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>
<!--</langsyntaxhighlight>-->
 
=={{header|Picat}}==
===Constraint modelling===
<langsyntaxhighlight Picatlang="picat">import sat.
 
main =>
Line 530:
nl
end,
nl.</langsyntaxhighlight>
 
{{out}}
Line 555:
* 7 vs 12 must be played in the last round
 
<langsyntaxhighlight Picatlang="picat">main =>
nolog,
N = 12,
Line 563:
[7,12,N-1]],
tournament_cp(N, NumRounds,NumPairs,Extras,X,Bye),
print_tournament(X,NumRounds,NumPairs,Bye).</langsyntaxhighlight>
 
{{out}}
Line 585:
Here the cp solver is used since it's faster than the sat solver for generating all solutions.
 
<langsyntaxhighlight Picatlang="picat">import cp.
 
main =>
Line 591:
Count = count_all(tournament_cp(N, _NumRounds,_NumPairs,_Extras,_X,_Bye)),
println(N=Count)
end.</langsyntaxhighlight>
 
{{out}}
Line 603:
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" perl6line>my @players = (1,0)[$_%2] .. $_ given 12;
my $half = +@players div 2;
my $round = 0;
Line 611:
@players[1..*].=rotate(-1);
last if [<] @players;
}</langsyntaxhighlight>
{{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}}==
<langsyntaxhighlight lang="ruby">def round_robin( n )
rotating_players = (2..n).map(&:to_s) #player 1 to be added later
rotating_players << "bye" if n.odd?
Line 642:
puts
end
</syntaxhighlight>
</lang>
{{out}}
<pre>Round 1
Line 691:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang="ecmascript">import "./fmt" for 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)</langsyntaxhighlight>
 
{{out}}
Line 746:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">def N = 12; \number of players (must be even)
int I, Player(N+1), Round, Temp;
[for I:= 1 to N do Player(I):= I;
Line 762:
Player(2):= Temp;
];
]</langsyntaxhighlight>
 
{{out}}
10,327

edits