My son is in the third grade and his math homework is to play games. The other night we played one that really got me thinking. Each player makes a 4×4 board and puts in any even number between 8 and 48 in every box (note there are more then 16 to choose from and that you can have repeats if you like). I just used the first 16 numbers (8-38) randomly on my grid. Then you roll 4 6-sided dice, add up the total, and then double it (so it’s testing low integer adding and doubling for the homework). You play until someone gets four in a row. As we played we both noticed that 28 kept coming up. I had it once on my board and he didn’t have it at all, so it really just kept extending the game. I told him that 28 would be expected to be the most common (avg roll is 3.5 and 3.5 x 4 x 2 = 28) so we got talking about whether next time we should try a board with all 28s. This post is all about what I learned when trying just that.
I decided to code up the game in Mathematica (this is the century of the decade of the year of the week of the hour of code after all). The low hanging fruit was to match an all-28 board against a board with random numbers on it without any repeats. It’s low-hanging because not having repeats means I don’t have to teach Mathematica how to make a choice when a repeated number is rolled (see below for my try at that). To simulate a roll I just produce 4 random integers between 1 and 6, add them, and double them. Here’s a plot of the probability of each roll:
To check if a bingo (four in a row) happens, I just check the board after each roll for any possible bingos.
Instead of playing matches, I just calculated how many rolls it would take to get a bingo for each type of board. Here’s a histogram of 1000 runs for each type (each bin is the count of the runs that took that many rolls to get a bingo for both types of boards).
I was a little surprised by this result. The random boards beat the all 28s board by a fair margin (on average). Did it surprise you?
So then I started wondering about better boards. I realized that if I wanted to do boards with some repeats on them, I’d have to teach Mathematica an effective strategy for making decisions. For example, say you rolled a 22 and you had 3 22s on your board. How do you decide where to put your bingo marker?
[pause while the reader considers]
What I decided to go with was to go for the spots that help out as many potential bingos as possible. That means corners and the inner square are worth more than non-corner edges. What I mean is that a corner spot could be a part of 3 potential bingos (left-right, down-up, and diagonal). The same is true for the inner square. But the non-corner edge spots only have left-right and up-down. So, if given a choice, it’ll go with one of the better ones. If all choices are in the same sort of spot (either all good or all slightly-less-good) then just do it randomly. However, if any of the choices gives you a bingo, I go with that one.
First I tried boards with randomly selected possibilities on each space. This allowed for repeats, since each space re-ran the random selection. Then I made boards where the randomness just mentioned was weighted by the probability expectation seen above. Here’s a comparison of all 4 types of boards:
It’s really interesting to see that the all 28s board is the worst, on average, even though we expected it to be better based on our (very limited) experience. It’s also interesting to see that the average number of rolls for a bingo is half as much for the weighted random (with repeats) board.
So what’s the best board? I don’t know, but what I did was generate 100 weighted-random boards and play 100 games with each. I then looked for the one with the lowest average. Here’s the winning board:
26 40 24 22
18 36 34 18
38 30 36 26
32 20 26 34
And here’s a histogram of running that board 1000 times:
Note that once it got a bingo in four consecutive rolls! Also note that the board doesn’t have any 28s in it!
Ok, that’s my fun for the week/day/hour of code. I hope you enjoyed it. Thoughts? Here are some starters for you:
- I’m in your son’s class, thanks! But I tried your best board and my friend beat me once. Therefore this is all wrong.
- I’m your son’s teacher and I really wish you hadn’t posted this. Now every single time my students play they tie since they always use the same board.
- I’m a lawyer at a Bingo ™ board manufacturer. I need your mailing address to send a cease and desist letter.
- Here’s a better idea for an algorithm to deal with the choices that need to be made when you have a repeat board, because the one you used is dumb.
- Thanks for this! Now I can quit school and stick it to the casinos!
- Why did you only run 100 boards at the end. What, you didn’t want to stay up even later on a Friday night to let it run longer? Wimp.
- I don’t believe this. The all 28s board should have trumped everything. You must have a mistake in your code.