Skip to content
Vamshi Jandhyala

Books · The Riddler

Chapter 79

Can You Bat .299 In 299 Games?

Riddler Express

You draw three coins, each independently a penny, nickel, dime or quarter (1,5,10,251, 5, 10, 25 cents) with equal chance, and buy strings of those lengths. What is the probability the three strings can form a triangle?

Solution

Three lengths form a triangle exactly when the longest is shorter than the sum of the other two. With ordered draws there are 43=644^3 = 64 equally likely triples; checking the triangle inequality, 2222 of them qualify, so Pr(triangle)=2264=11320.344.\Pr(\text{triangle}) = \frac{22}{64} = \boxed{\tfrac{11}{32} \approx 0.344}. The quarter is the spoiler: at 2525 it dwarfs the other coins, so any triple containing a quarter needs two more sizeable coins to reach past it, and most do not.

The computation

Enumerate all 6464 coin triples and count those satisfying the triangle inequality.

from fractions import Fraction as F
from itertools import product
coins = [1, 5, 10, 25]
good = sum(x + y > z and x + z > y and y + z > x
           for x, y, z in product(coins, repeat=3))
print(F(good, 64))                             # 11/32

Riddler Classic

A player has four at-bats per game, so after gg games their average is h/(4g)h/(4g) for some whole number of hits hh. For many gg there is an hh making the rounded average (to three decimals) equal g/1000g/1000. What is the largest gg for which no such hh exists?

Solution

For a given number of games gg, you can hit anywhere from 00 to 4g4g times, giving averages 0,14g,24g,,10, \tfrac{1}{4g}, \tfrac{2}{4g}, \dots, 1 in steps of 14g\tfrac{1}{4g}. A matching season needs one of these, rounded to three places, to equal g/1000g/1000. When gg is large the steps 14g\tfrac{1}{4g} are tiny and some hit count always rounds correctly, but for small gg the gaps are coarse enough to skip the target. Scanning downwards, the largest gg with no workable hit count is 239.\boxed{239.} With 239239 games the available averages step by 1956\tfrac{1}{956}, and none of them rounds to 0.2390.239.

The computation

For each gg from large to small, test every possible hit count and stop at the first gg for which none rounds to g/1000g/1000.

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