1/13/2012

An Arduino simulation of a blind draw scenario for a football pool

A friend at work proposed an interesting problem to me last week.  He told me about a football pool he and 5 others were doing.  The twelve teams that made the NFL playoffs were put into a hat.  Each of the 6 people blindly draw two teams.  Each person puts up 20 bucks.  If you drew the team that made it to the superbowl and lost, you got the 20 back.  If you drew the team that won the superbowl, you'd win 100 bucks.

So, out of 12 teams, there were 2 winners and 10 losers.  His question is "does it matter which order the participants draw their teams in?"  I told him I didn't think it mattered.  He seemed to think differently.

The dilemma is - the first person to draw was assured that the winner was still in the hat, but there were also more losers in the hat.  The last person to draw could many times be drawing dead, with the winner already having been drawn.  Long story short - I didn't think it mattered which order you drew in, while he thought it was clearly better to choose last.

I don't know how to do the math, so I proposed a computer simulation instead.  To simplify the simulation, I will have only one winner and five losers.  There will be six people drawing randomly, and the first person to draw the number '2' out of numbers 1-6 will be declared the winner for that round.  I'll keep track how many times each drawing position picks the winner, then run the simulation a large number of times.  100,000 iterations ought to be sufficient.

A quick pseudocode for the program:
1. Define six variables to store the results in.
2. Pick a random number for player1, player2, etc until the number '2' is drawn.
3. As losers are drawn, remove those numbers from the random possibilities.
4. Add 1 to the total for the winning player.
5. Repeat in a for loop and report results every 1000 iterations.

Here's the code I have so far...it's not working yet.  On test runs, I am getting more than 32,000 wins total out of  32,000 draws.  There must be some logical problem with my if..else construction.  I'll update this post when I get it fixed.  If someone can see my error, please chime in.

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
randomSeed(analogRead(0));
int player1,player2,player3,player4,player5,player6,iterations,i;
iterations = 32000;
// Pick a random number for the current player.  If the current
// player picks '1', add 1 to their total.  Otherwise draw again
// for the next player, subtracting 1 from the number of picks to
// draw from.
for (i = 0;i<iterations;i++){
if (random(1,7)==1) {player1++;}
else if (random(1,6)==1) {player2++;}
else if (random(1,5)==1) {player3++;}
else if (random(1,4)==1) {player4++;}
else if (random(1,3)==1) {player5++;}
else player6++;
}
// If the draw is a multiple of 1,000 - print the current results to the Serial monitor.
//if ((i%1000)==0) {
Serial.print("# ");
Serial.print(i);
Serial.print(" Plr 1: ");
Serial.print(player1);
Serial.print(" Plr 2: ");
Serial.print(player2);
Serial.print(" Plr 3: ");
Serial.print(player3);
Serial.print(" Plr 4: ");
Serial.print(player4);
Serial.print(" Plr 5: ");
Serial.print(player5);
Serial.print(" Plr 6: ");
Serial.print(player6);
Serial.println("");
//}
}