The three rules of Ruby Q.:
-
Please do not post any solutions or spoiler discussion for this quiz
until
48 hours have passed from the time on this message. -
Support Ruby Q. by submitting ideas as often as you can:
- Enjoy!
Suggestion: A [QUIZ] in the subject of emails about the problem helps
everyone
on Ruby T. follow the discussion. Please reply to the original quiz
message,
if you can.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
by Demetrius Nunes
In a single-elimination tournament, there is usually a previously
established
ranking for the participating players or teams, such as that the best
players or
teams are matched against the worst ones. This is done this way so there
is a
higher chance for the top players/teams to meet in the final.
For example, in a small 8-player tournament, there would be 3 rounds.
This first
round would be setup like this:
Round 1
1 x 8
2 x 7
3 x 6
4 x 5
This is easy enough. The tough part is arranging the pairing for the
following
rounds respecting the best vs worst rule, so, imagining that all the
favorites
won their games, we would have 1x4 and 2x3 in round 2 and then finally
1x2 in
the final. For this to happen, the tournament would have to be arranged
this
way:
R1 R2 R3
============
1
---
|---
--- |
8 |
|---
4 | |
--- | |
|--- |
--- |
5 |
|----
2 |
--- |
|--- |
--- | |
7 | |
|---
3 |
--- |
|---
---
6
If the numbers of players/teams is not a potency of 2, then the top
players
would have a “bye” in the first round, so, a 6-player draw would go like
this:
R1 R2 R3
============
1
---
|---
--- |
bye |
|---
4 | |
--- | |
|--- |
--- |
5 |
|----
2 |
--- |
|--- |
--- | |
bye | |
|---
3 |
--- |
|---
---
6
So, this quiz is about writing a single-elimination tournament generator
for any
number of players/teams obeying the best vs worst rule in all rounds.
For a quick look at correct answers see this “got-the-job-done”
javascript/html
implementation at:
http://www.crowsdarts.com/brackets/playoff-chart.html
We are looking for correct data modeling and calculation, not for
correct
presentation output of the tournament draw, but it would be nice to
implement a
#to_s output like the ones seen above (or even better: how about a
beautiful
RMagick generated image?!). In all cases, keep the model and
presentation
cleanly separated.