Skip to content
Vamshi Jandhyala

Books · The Riddler

Chapter 49

Can You Hunt For The Mysterious Numbers?

Riddler Express

On “You Bet Your Fife,” a real number is chosen uniformly between 00 and 100100. 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 gg, you win gg when the hidden number XX exceeds gg, which happens with probability 100g100\tfrac{100-g}{100}, and nothing otherwise. So your expected winnings are E[winnings]=g100g100=g(100g)100,\mathbb{E}[\text{winnings}] = g\cdot\frac{100-g}{100} = \frac{g(100-g)}{100}, a downward parabola in gg maximized where g=100gg = 100 - g, that is at g=50,E[winnings]=5050100=$25.g = \boxed{50}, \qquad \mathbb{E}[\text{winnings}] = \frac{50\cdot 50}{100} = \$25. 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 (294,216,135,98,112,84,245,40294, 216, 135, 98, 112, 84, 245, 40), and the products of the hundreds, tens and ones digits down the columns are 8,890,5608{,}890{,}560, 156,800156{,}800 and 55,56655{,}566. Find all eight numbers.

image

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: 776, 983, 953, 727, 827, 743, 577, 851.\boxed{776,\ 983,\ 953,\ 727,\ 827,\ 743,\ 577,\ 851.} A quick check: the hundreds digits multiply to 79978758=8,890,5607\cdot9\cdot9\cdot7\cdot8\cdot7\cdot5\cdot8 = 8{,}890{,}560, 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']