# Thomas Eckert

< writing /

### 10

07 Mar 2018 | Seattle, WA

Inspired by a question in Gayle Laakmann McDowell's Cracking the Coding Interview.

Let's say a friend challenges you to choose one of two games on the basketball court:

1. You have one chance to make one shot.
2. You have three chances to make two or more shots.

You want to win and you know the exact probability of making a shot, $$p$$. Which game do you have a better chance of winning?

#### Chance of winning Game One

This game consists of one chance to make one shot. Because the likelihood of making a shot is known to be $$p$$, the chance of winning is also $$p$$. Let's write this as $$s_1(p) = p.$$

#### Chance of winning Game Two

The math gets a little trickier here. Because you must make at least two of three shots, there are four ways to win this game:

First Second Third

The probabilty of making all three shots is the probability of making the first shot times making the second shot times making the third shot: $$p\cdot p\cdot p = p^3$$.

The probability of making two out of three shots is the probability of making two shots, $$p^2$$, times the probabilty of not making one shot, $$1-p$$. There are three chances for this to happen. So combined, this is: $$3p^2(1-p)$$.

We add the probability of making all shots to the probability of making two of three and get $$s_2(p) = p^3 +3p^2(1-p) = 3p^2 -2p^3.$$

#### Playing the Game

Now the time has come to choose which game to play. The chance of winning each game depends upon the probability $$p$$. Let's how the chance of winning is affected by the change in probability using a plot.

We can see that if our probability of making a single shot is less than 0.5, game one is the best bet. If that probability is greater than 0.5, game two is the best. If our probability of making a single shot is exactly 0.5, we have the same chance of winning either game.