{{ message }}

Instantly share code, notes, and snippets.

# mrichards42/riddler_hoops.md Secret

Last active Aug 25, 2018

## Rock-Paper-Scissors

There are 9 permutations of 2 players playing rock-paper-scissors. 3 of those permutations lead to ties: Rock-Rock, Paper-Paper, Scissors-Scissors.

``````
1 game + (1/3)(another game)
= 1 game + (1/3)(1 game + (1/3)(another game)) . . .
= Σ (1/3)n
= 3/2 games
``````

If each round of rock-paper-scissors takes 1 second, this means the average complete game of rock-paper-scissors should take 1.5 seconds.

## Hoop jumping

### 2 Hoops

Let's start with a small game of 2 hoops. With 2 hoops, each player makes 1 jump, then plays a game of rock-paper-scissors. I'll use the following notation for this:

``````
H(hoops ahead of you) = jumps + rock-paper-scissors-games
``````

So

``````
H2 = 1 + R
``````

Once one player wins, they will always have 1 hoop ahead of them, so this can be notated like:

``````
H2 = 1 + R + H1
``````

With 1 hoop ahead of them, the two players make 1 jump into the same hoop. Half the time the same player wins (thus winning the game), and the other half of the time the other player wins, leaving 1 more hoop ahead of them:

``````
H1 = 1 + R + (1/2)(0 [the game is over]) + (1/2)H1
= 1 + R + (1/2)H1
= Σ (1/2)n(1 + R)
= 2 (1 + R)
= 2 + 2R
``````

Thus

``````
H2 = 1 + R + H1
= 1 + R + 2 + 2R
= 3 + 3R
= 3 + 3 * 1.5
= 7.5 seconds
``````

### 8 Hoops

The same logic can be applied to more hoops. The initial equations for 8 hoops looks like:

``````
H1 = 1 + R + (1/2)H7
H2 = 1 + R + (1/2)H1 + (1/2)H7
H3 = 2 + R + (1/2)H1 + (1/2)H6
H4 = 2 + R + (1/2)H2 + (1/2)H6
H5 = 3 + R + (1/2)H2 + (1/2)H5
H6 = 3 + R + (1/2)H3 + (1/2)H5
H7 = 4 + R + (1/2)H3 + (1/2)H4
H8 = 4 + R + H4
``````

This can eventually be reduced to

``````
H8 = 36 + 15R
= 58.5 seconds
``````

### More Hoops

If you calculate this out for 1 - 8 hoops a pattern starts to emerge:

``````
1 hoop  =  1 +  1R
2 hoops =  3 +  3R
3 hoops =  6 +  5R
4 hoops = 10 +  7R
5 hoops = 15 +  9R
6 hoops = 21 + 11R
7 hoops = 28 + 13R
8 hoops = 36 + 15R
``````

I calculated 1, 2, 3, 4, and 8 hoops by hand, then double-checked my math by running a simulaton (python code included in the gist).

This turns into the following formula:

``````
seconds for n hoops = (Σ n) + (2n - 1)R
= (n * (n + 1))/2 + (2n - 1)(3/2)
= (n2 + 7n - 3)/2
``````

Solving for 1800 seconds (30 minutes) gives us ~56.63. Round that up to 57 to get an average game that lasts more than 30 minutes.