How to resolve the algorithm Round-robin tournament schedule step by step in the J programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Round-robin tournament schedule step by step in the J programming language
Table of Contents
Problem Statement
A round-robin tournament is also known as an all-play-all-tournament; each participant plays every other participant once. For N participants the number of rounds is N-1 if N is an even number. When there are an odd number of participants then each round one contestor has no opponent (AKA as a "bye"). The number of rounds is N in that case. Write a program that prints out a tournament schedule for 12 participants (represented by numbers 1 to 12).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Round-robin tournament schedule step by step in the J programming language
Source code in the j programming language
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.
}}
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
,/"2(' ',_2&{.@[,':',2&{.@])&":/"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
You may also check:How to resolve the algorithm String concatenation step by step in the SAS programming language
You may also check:How to resolve the algorithm Strip block comments step by step in the VBA programming language
You may also check:How to resolve the algorithm File extension is in extensions list step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Iterated digits squaring step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Partial function application step by step in the Mathematica/Wolfram Language programming language