Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2003
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: a challenge/problem.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg40082] RE: [mg40058] a challenge/problem.
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Wed, 19 Mar 2003 03:22:49 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

>-----Original Message-----
>From: Simon... [mailto:devnull at linux.org]
To: mathgroup at smc.vnet.net
>Sent: Tuesday, March 18, 2003 8:21 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg40082] [mg40058] a challenge/problem.
>
>
>Hi,
>
>I've got a puzzle, im not sure how to solve, a friend of mine asked me to
>make a program that given a number of teams (which must be more than 4 but
>other than that just dividable by 2) - now, there is teams\2 matches in a
>round, and no team must play more than 1 match in a round (making the
number
>of rounds teams-1).
>
>so if there is 10 teams, then there is 9 rounds, and 5 matches in each
>round, with a total of 45 matches.
>
>a list of combined matches could look like this
>
>10 vs. 9
>10 vs. 8
>10 vs. 7
>10 vs. 6
>10 vs. 5
>10 vs. 4
>10 vs. 3
>10 vs. 2
>10 vs. 1
>9 vs. 8
>9 vs. 7
>9 vs. 6
>9 vs. 5
>9 vs. 4
>9 vs. 3
>9 vs. 2
>9 vs. 1
>8 vs. 7
>8 vs. 6
>8 vs. 5
>8 vs. 4
>8 vs. 3
>8 vs. 2
>8 vs. 1
>7 vs. 6
>7 vs. 5
>7 vs. 4
>7 vs. 3
>7 vs. 2
>7 vs. 1
>6 vs. 5
>6 vs. 4
>6 vs. 3
>6 vs. 2
>6 vs. 1
>5 vs. 4
>5 vs. 3
>5 vs. 2
>5 vs. 1
>4 vs. 3
>4 vs. 2
>4 vs. 1
>3 vs. 2
>3 vs. 1
>2 vs. 1
>
>which was generated with this algorithm (which is perl if you should be
>interested):
>
>#make the ordered list of matches
> $current = $teams;  #current is now = 10
> while ($current > 1)
> {
>        $next_team = $current-1;
>
>        while ($next_team >= 1)
>       {
>             $matches[$counter] = "$current vs. $next_team"; 
>#array to hold the matches
>             $counter++;
>             $next_team--;
>        }
>        $current--;
> }
>
>
>now how do i make the teams-1 rounds with 5 matches in each, where a team
>does not play 2 matches.... ??
>
>Thanks for any help !
>Kindly
>-Simon
>ps. this message is posted to various math groups.
>
>
>
>

Simon,

it's not quite clear to me, what you finally want to know. Anyway, you may
translate that perl code quite literally to Mathematica:

In[56]:= $teams = 10;
In[57]:=
(* make the ordered list of matches *)
$current = $teams; (* current is now = 10 *)
$counter = 1; Clear[$matches];
While[ ($current > 1),
($nextTeam = $current - 1;
    While[ ($nextTeam >= 1) , ($matches[$counter] = 
          ToString[$current] <> " vs. " <> ToString[$nextTeam];(* 
          array to hold the matches *)
         $counter++;
        $nextTeam--;) ];
    $current--;)]

In[60]:= Array[$matches, {$teams*($teams - 1)/2}] // TableForm


This just gives that list of pairings (matches) above. You may run that code
with any number of teams, e.g. $Teams = 11 or 0, 1, 2, 3, ...


It does not give the matches grouped into rounds however. For that there are
more possible solutions. 

What we did, when playing an impromptu quick chess tournament, was this:
align all tables in the room to a row, put the chess-boards onto the table
in alternating orientation of white and black. Of course chairs were placed
accordingly.

Now depending on the number of players:

If they were odd, an additional chair was put at the head of the row of
tables. Then we took place at the boards, one person offside at the head,
and tack, tack, tack,... moved the chess-men. After at most 10 minutes, all
games were over, we put up the fallen kings and all their royal househould,
and each of us moved a chair clockwise (now a different person at the head,
if any). The tournament was over, when everyone arrived at his or her
starting seat.

If the number of players, where even, then no extra chair was needed, of
course, but then the player #1 kept his seat and didn't move up, whereas all
others rotated. Instead player #1 had to turn the chessboard after every
game.


This translates to Mathematica:

In[157]:=
rounds[nteams_Integer?EvenQ] /; nteams > 1 := 
  Module[{t = Range[nteams]}, 
      MapIndexed[
        Module[{evenround = EvenQ[First[#2]]}, 
            Prepend[MapIndexed[
                Inner[#1[#2] &, 
                    If[EvenQ[First[#2]] || evenround && First[#2] === 1, 
                        Reverse, Identity][{White, Black}], #1, List] &, 
                Transpose[MapAt[Reverse, Partition[#1, Floor[nteams/2]],
2]]],
               "Round " <> ToString[First[#2]] <> ":"]] &, 
        Table[Prepend[RotateRight[Rest[t], r], First[t]], {r, 0, 
            nteams - 2}]]] // TableForm

In[158]:=
rounds[nteams_Integer?OddQ] /; nteams > 1 := 
  Module[{t = Range[nteams]}, 
      MapIndexed[
        Prepend[MapIndexed[
              Inner[#1[#2] &, 
                  If[EvenQ[First[#2]], Reverse, Identity][{White, Black}],
#1,
                   List] &, 
              Transpose[MapAt[Reverse, Partition[#, Floor[nteams/2]], 2]]], 
            "Round " <> ToString[First[#2]] <> ":"] &, 
        Table[RotateRight[t, r], {r, 0, nteams - 1}]]] // TableForm


In[159]:= rounds[8]
Out[159]//TableForm=

Round 1: White[1]  Black[2]  White[3]  Black[4]
         Black[8]  White[7]  Black[6]  White[5]

Round 2: Black[1]  Black[8]  White[2]  Black[3]
         White[7]  White[6]  Black[5]  White[4]

Round 3: White[1]  Black[7]  White[8]  Black[2]
         Black[6]  White[5]  Black[4]  White[3]

Round 4: Black[1]  Black[6]  White[7]  Black[8]
         White[5]  White[4]  Black[3]  White[2]

Round 5: White[1]  Black[5]  White[6]  Black[7]
         Black[4]  White[3]  Black[2]  White[8]

Round 6: Black[1]  Black[4]  White[5]  Black[6]
         White[3]  White[2]  Black[8]  White[7]

Round 7: White[1]  Black[3]  White[4]  Black[5]
         Black[2]  White[8]  Black[7]  White[6]


In[160]:= rounds[9]
Out[160]//TableForm=

Round 1: White[1]  Black[2]  White[3]  Black[4]
         Black[8]  White[7]  Black[6]  White[5]

Round 2: White[9]  Black[1]  White[2]  Black[3]
         Black[7]  White[6]  Black[5]  White[4]

Round 3: White[8]  Black[9]  White[1]  Black[2]
         Black[6]  White[5]  Black[4]  White[3]

Round 4: White[7]  Black[8]  White[9]  Black[1]
         Black[5]  White[4]  Black[3]  White[2]

Round 5: White[6]  Black[7]  White[8]  Black[9]
         Black[4]  White[3]  Black[2]  White[1]

Round 6: White[5]  Black[6]  White[7]  Black[8]
         Black[3]  White[2]  Black[1]  White[9]

Round 7: White[4]  Black[5]  White[6]  Black[7]
         Black[2]  White[1]  Black[9]  White[8]

Round 8: White[3]  Black[4]  White[5]  Black[6]
         Black[1]  White[9]  White[8]  White[7]

Round 9: White[2]  Black[3]  White[4]  Black[5]
         Black[9]  White[8]  Black[7]  White[6]


--
Hartmut Wolf



  • Prev by Date: Re: Re: Don't understand Plot behavior
  • Next by Date: combinatorics problem
  • Previous by thread: a challenge/problem.
  • Next by thread: Re: a challenge/problem.