## Riddler Express

You have three coins in your pocket, each of which can be a penny, nickel, dime or quarter with equal probability. You might have three different coins, three of the same coin or two coins that are the same and one that is different.

Each of these coins can buy you a string whose length in centimeters equals the value of the coin in cents, i.e., the penny buys 1 cm of string, the nickel buys 5 cm of string, etc. After purchasing your three lengths of string, what is the probability that they can be the side lengths of a triangle?

## Computational Solution 1

We first look at all possible combinations of three coins. As all the combinations are equally likely, we divide the number of combinations where the three coin values form a triangle by the total number of combinations. The probability that the purchased strings can be the side lengths of a triangle is \(\bf{0.34375}\).

```
from itertools import product
= [1,5,10,25]
coins = 0
succ = list(product(*[coins]*3))
coin_combs for x,y,z in coin_combs:
if x + y > z and x + z > y and y + z > x:
+= 1
succ print(succ/len(coin_combs))
```

## Computational Solution 2

For each run of the Monte Carlo simulation, we choose \(3\) coins randomly with replacement from the set \(\{1,5,10,25\}\) and check if a triangle can be formed with the coin values. The average count of successes is the probability that the purchased strings can be the side lengths of a triangle. The probability based on the simulation below is \(\bf{0.343}\).

```
from random import choices
= [1,5,10,25]
coins = 100000
runs = 0
succ for _ in range(runs):
= choices(coins, k=3)
x,y,z if x + y > z and x + z > y and y + z > x:
+= 1
succ print(succ/runs)
```

## Riddler Classic

Suppose a baseball player has four at-bats per game (not including walks), so their batting average is the number of hits they got divided by four times the number of games they played. For many games, it’s possible to have a corresponding batting average that, when rounded to three digits, equals the number of games divided by \(1,000\). For example, if a player typically gets one hit per game in their at-bats, then they could very well have a \(.250\) average over \(250\) games.

What is the greatest number of games for which it is not possible to have a matching rounded batting average? Again, assume four at-bats per game.

## Computational Solution

As per the code below, the number of games for which it is not possible to have a matching rounding batting average is \(\bf{239}\).

```
for g in range(1000, 1, -1):
if all([round(h/(4*g),3) != g/1000 for h in range(0, 4*g+1)]):
break
print(g)
```