I got a fun little puzzle, and a sincere doubt, so I thought to share it:
Immagine you are in a submarine with other nine fellas, the hull of the thing just badly cracked, and you all have to decide who is going to use the only oxygen tank available to save himself, the other nine will of course remain stuck into the submarine and die an horrible death.
So you and your mates devise a game: you are gonna play a variation of rock, paper scissor that works in the following way: at the count of one, two three you all are gonna play at the same time either rock, paper or scissor, if somebody plays an hand that beats all the other hands (that is really improbable since all the other hands must be identical to have this result) then he is the winner; if the result is mixed and there is no clear winner then we repeat the round until somebody by chance plays an hand that beats all other nine equal hands (also equal by chance of course). Assume that to play one round we need six seconds of time. Question is: what is the mean time for which you play before getting a winner? Me and my friends asked ourself this question and we come up with an answer of more or less $3.3$ hours.
But then, just to be safe, we coded a little program to play the game for us an high number of times, so we could verify empirically our reasoning. The code of the program (in Python) is the following:
import random
import matplotlib.pyplot as plt
import numpy as np
def result(hand1,hand2): #True=win
if(hand1==1):
if(hand2==2):
return True
elif(hand1==2):
if(hand2==3):
return True
elif(hand1==3):
if(hand2==1):
return True
else:
return False
def play():
num_players=10
mani = []
counter_wins=0
win=False
counter_cycles=0
while(True):
for i in range(0 , num_players): #generate play
hand=random.randint(1,3)
hands.append(hand)
for i in range(0,num_players): #i=player, j compare to players
for j in range(0,num_players):
if(not(i==j)):
if(result(hands[i],hands[j])):
counter_wins=counter_wins+1
if(counter_wins==(num_players-1)):
win=True
break
counter_wins=0
hands = []
counter_cycles=counter_cycles+1
if(win):
print("\nWin in " , counter_cycles , "cycles!\n Time: " , float(counter_cycles*6)/3600 , "hours!\n")
break
return float(counter_cycles*6)/3600
results = []
n_c=int(input("\nHow many games?\n"))
for i in range(0,n_c):
results.append(play())
mean = float(sum(risultati))/len(risultati)
print("\nThis is the mean:" , mean )
plt.hist(results, density=False, bins=100)
plt.ylabel('Number of games')
plt.xlabel('Hours');
plt.show()
If you indeed tryed to run this code you would see that the mean is more or less what predicted.
But then, just for fun, we decided to plot the result in an histogram (we played $100$ games and plotted the times of every game in $30$ bins), and the result shocked us: the data plotted follows an exponential distribution, and not a Gaussian centered around the mean as we expected. I encourage you to try the code for yourself. Why is this? What is going on? What makes the binned distribution shaped like an exponential? Is it an error in the code or this result has to do with the structure of the game itself?
Let $p$ be the probability that someone wins in a round.
The game stops at the first round with probability $p$.
Otherwise he game stops at the second round with probability $qp$.
Otherwise the game stops at the third round with probability $q^2p$.
Otherwise the game stops at the third round with probability $q^3p$.
...
This is clearly a geometric distribution. The expectation of the number of rounds is $\dfrac1p$.