Skip to content
Vamshi Jandhyala

Books · The Riddler

Chapter 70

Can You Decipher The Secret Message?

Riddler Express

Break a wand of length 1010 at any points you like and multiply the lengths of the pieces. What is the largest product? Extra credit: with a wand of length 100100?

Solution

Suppose you cut the wand of length LL into nn pieces. By the arithmetic–geometric mean inequality their product is largest when the pieces are equal, each L/nL/n, giving (L/n)n(L/n)^n. So the only real choice is how many pieces to make. Treating nn as continuous, (L/n)n(L/n)^n is maximised at n=L/en = L/e, and since nn must be a whole number we test the integers nearest L/eL/e.

For L=10L = 10, L/e3.68L/e \approx 3.68, so n=4n = 4 wins (it beats n=3n = 3), and (104)4=2.54=39.0625.\left(\frac{10}{4}\right)^4 = 2.5^4 = \boxed{39.0625}. For L=100L = 100, L/e36.8L/e \approx 36.8, so n=37n = 37, and (10037)379.47×1015.\left(\frac{100}{37}\right)^{37} \approx \boxed{9.47 \times 10^{15}}.

The computation

For each candidate piece count, equal pieces are optimal, so just maximise (L/n)n(L/n)^n over whole nn.

def best_product(L):
    n = max(range(1, L + 1), key=lambda n: (L / n)**n)
    return n, (L / n)**n
print(best_product(10))                        # (4, 39.0625)
print(best_product(100))                        # (37, 9.47e15)

Riddler Classic

In a sans-serif uppercase font, many letters are topologically equivalent (one can be continuously deformed into another without cutting or gluing). The coded message YIRTHA is equivalent, letter by letter, to exactly one English word. What is it?

Solution

Sort the letters by topological type, counting holes and loose ends. The classes are: a single arc with no holes (C, G, I, J, M, N, S, U, V, W, Z); one hole with one loose end (P, Q); one hole with two loose ends (A, R); a plain loop (D, O); two holes (B); a shape with three loose ends (E, F, T, Y); and one with four (H, K, X). Two letters decode to each other only if they share a class. Reading YIRTHA class by class, YE, IU, RR, TE, HK, AA,\texttt{Y} \to \texttt{E},\ \texttt{I} \to \texttt{U},\ \texttt{R} \to \texttt{R},\ \texttt{T} \to \texttt{E},\ \texttt{H} \to \texttt{K},\ \texttt{A} \to \texttt{A}, and the only six-letter English word whose letters fall in exactly these classes is EUREKA.\boxed{\text{EUREKA.}}

The computation

Replace each letter by its topological class, then scan the dictionary for the unique six-letter word matching the class pattern of YIRTHA.

import urllib.request
words = [w.decode().strip().upper() for w in
         urllib.request.urlopen("https://norvig.com/ngrams/enable1.txt")]
classes = ['AR', 'B', 'CGIJMNSUVWZ', 'DO', 'EFTY', 'HKX', 'PQ']
def cls(ch): return next(g for g in classes if ch in g)
pat = [cls(c) for c in "YIRTHA"]
print({w for w in words if len(w) == 6
       and all(c in g for c, g in zip(w, pat))})   # {'EUREKA'}