# FiveThirtyEight Riddler

## Will the Neurotic Basketball Player Make His Next Free Throw?

A basketball player is in the gym practicing free throws. He makes his first shot, then misses his second. This player tends to get inside his own head a little bit, so this isn’t good news. Specifically, the probability he hits any subsequent shot is equal to the overall percentage of shots that he’s made thus far. (His neuroses are very exacting.) His coach, who knows his psychological tendency and saw the first two shots, leaves the gym and doesn’t see the next 96 shots. The coach returns, and sees the player make shot No. 99. What is the probability, from the coach’s point of view, that he makes shot No. 100?

### Solution

We will solve by brute force: simulation!

# r
library(pbapply)

shootFreethrows <- function(){
shots <- c(1, 0)
for(i in 3:100){
p <- mean(shots)
shot <- sample(x = c(1, 0), size = 1, prob = c(p, 1 - p))
shots <- c(shots, shot)
}
if(shots[99] == 1){
return(shots[100])
}
}

shootFreethrowsRepeatedly <- function(){
results <- unlist(pbreplicate(10000000, shootFreethrows()))
return(mean(results))
}

shootFreethrowsRepeatedly()

After many, many (10,000,000) simulated games, we find that he makes his 100th freethrow 2/3rds of the time that he makes his 99th.

## How Long Will Your Smartphone Distract You From Family Dinner?

### Solution

When we simulate this situation, as I did 10,000,000 times, you get 9 minutes on average.

# python
import random

def waitForDinner():
a = random.sample((1,2,3,4,5), 1)[0]
b = random.sample((1,2,3,4,5), 1)[0]
while(a != b):
if(a > b):
b += random.sample((1,2,3,4,5), 1)[0]
else:
a += random.sample((1,2,3,4,5), 1)[0]
return a

def waitForDinnerRepeatedly():
waits = []
for i in range(10000000):
waits.append(waitForDinner())
return sum(waits) / len(waits)

waitForDinnerRepeatedly()