Skip to content
Vamshi Jandhyala

Books · The Riddler

Chapter 290

How High Can You Count With Menorah Math?

The Riddler for December 11, 2020. The Express encodes nights on a menorah readable from either side, and the Classic finds a hat-guessing strategy that guarantees a survivor.

Riddler Express

A menorah has eight candle positions (besides the central shamash), each lit or unlit. You want to encode as many distinct “nights” as possible, but the menorah is viewed from both the front and the back, so a pattern and its left–right reversal must indicate the same night. What is the greatest number of nights you can represent?

The Riddler, FiveThirtyEight, December 11, 2020(original post)

Solution

Each of the 88 positions is a bit, giving 28=2562^8 = 256 patterns. A front viewer sees a pattern pp; a back viewer sees its reversal. To make the night unambiguous from either side, assign each night either a symmetric pattern (equal to its own reversal, so both sides agree) or a mirror pair of asymmetric patterns (front sees one, back sees the other, both decoding to the same night).

Symmetric patterns are fixed by their left half: 24=162^4 = 16 of them. The remaining 25616=240256 - 16 = 240 are asymmetric, forming 240/2=120240/2 = 120 mirror pairs. Each symmetric pattern and each mirror pair encodes one night, so 16+120=13616 + 120 = \boxed{136} distinguishable nights, far more than ternary pair-coding (34=813^4 = 81) and beating a naive palindromes-only scheme (1616).

The computation

Encode every 88-bit pattern, group each with its reversal, and count the distinct unordered groups.

groups = set()
for p in range(256):
    bits = format(p, '08b')
    rev = bits[::-1]
    groups.add(frozenset({bits, rev}))   # a symmetric pattern pairs with itself
print(len(groups))                       # 136

The menorah can track 136136 nights.

Riddler Classic

Five citizens each get a red, green, or blue hat. They are split into a row of two (A,BA, B) and a row of three (C,D,EC, D, E); each row sees the other row but not itself, and each knows their own position. With no communication, all guess their own hat colour simultaneously. What strategy guarantees at least one correct guess?

The Riddler, FiveThirtyEight, December 11, 2020(original post)

Solution

Code the colours 0,1,20, 1, 2 and let the hat values be a,ba, b (row of two) and c,d,ec, d, e (row of three). The row of three sees a,ba, b; the row of two sees c,d,ec, d, e. A guaranteed strategy:

  • CC guesses aa, DD guesses bb, EE guesses (a+b)mod3(a + b) \bmod 3.

If any of C,D,EC, D, E is right, the group survives. So AA and BB may assume all three are wrong, which means aca \neq c, bdb \neq d, and (a+b)≢e(mod3)(a + b) \not\equiv e \pmod 3. Under those three constraints, with s=(ecd)mod3s = (e - c - d) \bmod 3:

  • AA guesses c+1c + 1 if s{0,1}s \in \{0, 1\}, else c+2c + 2 (mod 33);

  • BB guesses d+2d + 2 if s{0,2}s \in \{0, 2\}, else d+1d + 1 (mod 33).

Working through the three cases of ss, the two-to-four surviving (a,b)(a, b) possibilities are always covered by AA or BB, so whenever C,D,EC, D, E all fail, at least one of A,BA, B succeeds. Either way, at least one citizen always guesses correctly.\boxed{\text{at least one citizen always guesses correctly.}}

The computation

Encode the strategy and check all 35=2433^5 = 243 hat assignments: in every case at least one guess is right.

import itertools
def survives(a, b, c, d, e):
    gC, gD, gE = a, b, (a + b) % 3            # row of three see A, B
    s = (e - c - d) % 3
    gA = (c + 1) % 3 if s in (0, 1) else (c + 2) % 3
    gB = (d + 2) % 3 if s in (0, 2) else (d + 1) % 3
    return gC == c or gD == d or gE == e or gA == a or gB == b
print(sum(survives(*t) for t in itertools.product(range(3), repeat=5)))  # 243

All 243243 colourings survive, so the strategy is guaranteed.