Round-robin tournament schedule: Difference between revisions

J draft
(J draft)
Line 279:
Same as Wren example.
</pre>
 
=={{header|J}}==
 
Implementation (using the wikipedia [[wikipedia:Round-robin_tournament#Circle_method|circle method]]):
 
<syntaxhighlight lang=J>circ=: {{
if. 1=2|y do.
assert. 1<y
<:(#~ [: */"1 *)"2 circ y+1
else.
ids=. i.y
(-:y) ({.,.|.@}.)"_1] 0,.(}:ids)|."0 1}.ids
end.
}}</syntaxhighlight>
 
Task example:
<syntaxhighlight lang=J> rplc&'j:'"1":j./"1>:circ 12
1:12 2:11 3:10 4:9 5:8 6:7
1:2 3:12 4:11 5:10 6:9 7:8
1:3 4:2 5:12 6:11 7:10 8:9
1:4 5:3 6:2 7:12 8:11 9:10
1:5 6:4 7:3 8:2 9:12 10:11
1:6 7:5 8:4 9:3 10:2 11:12
1:7 8:6 9:5 10:4 11:3 12:2
1:8 9:7 10:6 11:5 12:4 2:3
1:9 10:8 11:7 12:6 2:5 3:4
1:10 11:9 12:8 2:7 3:6 4:5
1:11 12:10 2:9 3:8 4:7 5:6</syntaxhighlight>
 
(Here, <code>circ</code> uses index values which start at zero, so we need to add 1 to every index. Then we form the id pairs as complex numbers, replace the 'j' used to separate real from imaginary in their character representation with ':' for a hopefully compact and easy-to-read display.)
 
 
=={{header|Julia}}==
6,951

edits