The code included is a simulated answer to a classic riddler challenge from 538:
Let’s call this game rock-paper-scissors-hop. Here is an idealized list of its rules:
- Kids stand at either end of N hoops.
- At the start of the game, one kid from each end starts hopping at a speed of one hoop per second until they run into each other, either in adjacent hoops or in the same hoop.
- At that point, they play rock-paper-scissors at a rate of one game per second until one of the kids wins.
- The loser goes back to their end of the hoops, a new kid immediately steps up at that end, and the winner and the new player hop until they run into each other.
- This process continues until someone reaches the opposing end. That player’s team wins!
- You’ve just been hired as the gym teacher at Riddler Elementary. You’re having a bad day, and you want to make sure the kids stay occupied for the entire class. If you put down eight hoops, how long on average will the game last? How many hoops should you put down if you want the game to last for the entire 30-minute period, on average?
The Python simulation asks the user to choose the length of time they'd like the game to last (the default is 30 minutes), and set the number of simulations. There are two questions to answer here:
This comes out to a little over 5 minutes (approximately 5 minutes and 15 seconds). Here is the average length of time as we increase the number of hoops:
{8: 5.25, 9: 10.60, 10: 21.38, 11: 42.66, 12: 85.90, 13: 171.04, 14: 345.51, 15: 688.96}
The time essentially doubles with each added hoop. The run time to simulate past 15 hoops gets very long - a game with 15 hoops would already take pretty much the whole school day. We can also include the 95% confidence intervals, which show just how much variation there is as the number of hoops goes up. The upper range with 15 hoops starts to look like a classic 3-4 day game of cricket.
If we set the threshold at 50%, the cut-off is just over 11 hoops
{8: 0.004, 9: 0.06, 10: 0.208, 11: 0.479, 12: 0.686, 13: 0.837, 14: 0.923, 15: 0.964}
so if we're really feeling lazy we might put out 12 hoops just to be safe. At 15 hoops you could pretty much take a nap 19 out of 20 class periods (although it sounds like this is a pretty loud game).