Chapter 49
Can You Hunt For The Mysterious Numbers?
Riddler Express
On “You Bet Your Fife,” a real number is chosen uniformly between and . You guess a value; if your guess is less than the number you win a fife worth exactly your guess, otherwise nothing. What should you guess to maximize your expected winnings?
Solution
If you guess , you win when the hidden number exceeds , which happens with probability , and nothing otherwise. So your expected winnings are a downward parabola in maximized where , that is at The balance is between asking for more and the rising chance of winning nothing, and it tips exactly at the halfway mark.
The computation
Maximize the expected-winnings parabola.
best = max(range(101), key=lambda g: g * (100 - g) / 100)
print(best, best * (100 - best) / 100) # 50, 25.0
Riddler Classic
Eight three-digit numbers fill the rows of a table. The product of each number’s three digits is given at the right (), and the products of the hundreds, tens and ones digits down the columns are , and . Find all eight numbers.

Solution
Each row’s product factors into three digits in only a few ways, and the three column products pin down which factorization each row must use. A short backtracking search, trying each row’s digit triples and pruning whenever a running column product overshoots its target, finds a unique solution: A quick check: the hundreds digits multiply to , and the row and column products all match.
The computation
For each row list the digit triples whose product matches; then search across rows for the one combination whose hundreds, tens and ones digits multiply to the three column totals.
rows = [294, 216, 135, 98, 112, 84, 245, 40]
cols = (8890560, 156800, 55566)
def triples(p):
return [(h, t, o) for h in range(1, 10) for t in range(1, 10)
for o in range(1, 10) if h*t*o == p]
opts = [triples(p) for p in rows]
sols = []
def search(i, prod, acc):
if any(prod[c] > cols[c] for c in range(3)):
return
if i == len(rows):
if prod == list(cols): sols.append(acc)
return
for h, t, o in opts[i]:
search(i + 1, [prod[0]*h, prod[1]*t, prod[2]*o], acc + [f"{h}{t}{o}"])
search(0, [1, 1, 1], [])
print(len(sols), sols[0]) # 1, ['776','983','953','727','827','743','577','851']