14 Jan 2005 18:09
[QUIZ] Perl 'Medium' QOTW - Tournament Schedule
IMPORTANT: Please do not post solutions, hints, or other spoilers
until at least 60 hours after the date of this message.
Thanks.
IMPORTANT: S'il vous plaît, attendez au minimum 60 heures après la
date de ce message avant de poster solutions, indices ou autres
révélations. Merci.
BELANGRIJK: Stuur aub geen oplossingen, hints of andere tips in de
eerste 60 uur na het verzendingstijdstip van dit
bericht. Waarvoor dank.
VNIMANIE: Pozhalujsta ne shlite reshenija, nameki na reshenija, i
voobshe lyubye podskazki v techenie po krajnej mere 60 chasov
ot daty etogo soobshenija. Spasibo.
Qing3 Zhu4Yi4: Qing3 Ning2 Deng3Dao4 Jie1Dao4 Ben3 Xin4Xi2 Zhi1Hou4 60
Xiao3Shi2, Zai4 Fa1Biao3 Jie3Da2, Ti2Shi4, Huo4 Qi2Ta1 Hui4
Xie4Lou4 Da2An4 De5 Jian4Yi4. Xie4Xie4.
You are given N sport teams (where N is even) who wish to compete against each
other. Each team should have a match against any other team once and only
once. Moreover, the tournament should take place in N-1 days, where in every
day, each team plays once against some other team. (for a total of N*(N-1)/2
matches, which is the number of possible matches).
Your mission is to write a Perl program that will allocate such a schedule.
The function in question would be called allocate_schedule() and will receive
a single scalar parameter, which is the number of the teams. It will return a
reference to an array of day allocations. Each day allocation will be a
reference to an array that for each index will specify the index of the team
that the team with the index in that array will compete against that day.
So for example:
allocate_schedule(2)
will return:
[[1, 0]];
allocate_schedule(4)
may return:
[[1,0,3,2],[2,3,0,1],[3,2,1,0]];
You can try solving the problem for an N that is a whole power of 2, as this
problem is easier.
Regards,
Shlomi Fish
---------------------------------------------------------------------
Shlomi Fish shlomif@...
Homepage: http://www.shlomifish.org/
Knuth is not God! It took him two days to build the Roman Empire.
RSS Feed