Chapter 213
How Many Crossword Puzzles Can You Make?
Riddler Express
Given a two-character, seven-segment display (the kind on a microwave clock), how many numbers can you make that are not ambiguous if the display happens to be upside down? For example, would not fit this criterion: upside-down it shows . The number is fine: upside-down it appears as something like “”, not a number.
The Riddler, FiveThirtyEight, January 18, 2019(original post)
Solution
The display shows two characters drawn with the standard seven-segment alphabet. When the display is rotated , two things happen at once: (i) each individual digit is rotated , and (ii) the order of the two positions swaps (the right digit becomes the left and vice versa).
The digit-flip table. Rotated , the standard seven-segment digits are and each rotate into a shape that is not any digit (a backwards , an -like glyph, an ). Write for the seven digits that survive a flip as a digit, and for the three that flip to non-digits.
When is the display ambiguous? A two-character display is read by another viewer (looking at it upside down) as , where is the rotation of a single character. The display is ambiguous when the flipped reading is a different valid two-digit number, that is, when and are both digits and . Equivalently, the display is not ambiguous in either of two disjoint cases:
Flip is not a number. At least one of or is in , so the flipped display contains a non-digit glyph and cannot be read as any number.
Flip is the same number. Both and are in , and , that is, and . The pairs satisfying , for are , seven pairs.
Counting. The total number of two-character displays is . The count of ambiguous displays is easier than the unambiguous: a display is ambiguous iff both and the flip is a different number. The number of with both in is , and the seven self-mapping pairs above are the ones that flip to themselves; the remaining flip to a different valid two-digit number, hence are ambiguous. So the unambiguous count is
The computation
Encode the problem directly: enumerate all two-character displays , apply the digit-flip table to each character, swap order, and count how many displays are not ambiguous in the sense of the prompt.
Build the digit-flip table.
For each display , compute the flipped reading.
Mark the display unambiguous if the flipped reading is not a valid number or equals .
Print the unambiguous count.
FLIP = {'0': '0', '1': '1', '2': '2', '5': '5', '8': '8',
'6': '9', '9': '6'} # 3, 4, 7 are absent: not digits
def flipped_reading(s):
return ''.join(FLIP.get(c, '?') for c in s[::-1])
count = 0
for n in range(100):
s = f"{n:02d}"
f = flipped_reading(s)
if '?' in f or f == s:
count += 1
print(f"Unambiguous two-character displays: {count}")
The script prints , matching the boxed answer.
Riddler Classic
Crossword grids obey a few rules. They are and rotationally symmetric (the grid looks the same when turned upside down). All maximal horizontal and vertical runs of white squares (“words”) are at least three squares long. Every white square is part of an across word and a down word. The grid is entirely connected: no islands of white squares separated from the rest by black squares. First question: how many such grids are there? Second question: how many are there with no “cheater squares”, that is, no black squares whose removal would not change the total word count? Extra credit: the Sunday grid, with and without cheater squares.
The Riddler, FiveThirtyEight, January 18, 2019(original post)
Solution
The puzzle is a counting problem with no known closed form at . The right setup is to state the constraints precisely, count exhaustively for small (where the answers are known), and then explain why the same enumeration becomes intractable at . The puzzle’s official write-up confirms that remains an open problem as of January 2019; the largest published exact count is Jim Ferry’s result, .
The constraints, formally. Let encode the grid, with for white and for black. Then is a valid crossword grid iff
Rotational symmetry. for all .
Word length. Every maximal run of s in any row or column has length .
Connectivity. The white squares form a single -connected component.
The third constraint “every white square is part of an across word and a down word” is implied by the word-length constraint: if a white square is in any row run, that row run has length , so the square is part of an across word; same for columns.
Small cases. Because of symmetry, a grid is determined by the cells in a representative half. For odd , that half has cells. For this is , well within exhaustive reach: symmetric layouts, of which only those satisfying word-length and connectivity survive. The brute count is which matches Laurent Lessard’s published enumeration in the official solution. The same brute approach handles small , but the search space doubles every two cells of the representative half: from , the count climbs into the millions by and the billions by . Direct exhaustive enumeration at is far out of reach (one representative half has cells; symmetric layouts), and even the cleverest dynamic-programming approaches reported in the official did not pin down the exact count.
The headline. The exact count (with or without cheater squares) is open. The largest exact value the official cites is the count from Jim Ferry, The puzzle’s question is therefore best answered by reporting the small- enumeration that the computation below performs in full, and stating the open status at .
The computation
Encode the rules directly: iterate over all -symmetric black/white assignments on a representative half, reconstruct the full grid, check word-length and connectivity, and count valid grids. Run it up to for an exact match against the published total; the same code handles in seconds and stops being feasible past .
Enumerate the orbits of the cell positions under rotation; each orbit is set black or white as a single bit.
For each bitmask, fill in the full grid using the orbit map.
Check that every maximal white run in every row and every column has length .
Check that the white cells form one -connected component.
Tally the valid grids and print.
from collections import deque
def count_grids(N):
orbits, seen = [], set()
for r in range(N):
for c in range(N):
if (r, c) in seen:
continue
ro, co = N - 1 - r, N - 1 - c
orbit = {(r, c), (ro, co)}
for p in orbit:
seen.add(p)
orbits.append(tuple(orbit))
M = len(orbits)
def valid(g):
for r in range(N):
run = 0
for c in range(N):
if g[r][c] == 0:
run += 1
else:
if 0 < run < 3:
return False
run = 0
if 0 < run < 3:
return False
for c in range(N):
run = 0
for r in range(N):
if g[r][c] == 0:
run += 1
else:
if 0 < run < 3:
return False
run = 0
if 0 < run < 3:
return False
whites = [(r, c) for r in range(N)
for c in range(N) if g[r][c] == 0]
if not whites:
return False
seen_w = {whites[0]}
q = deque([whites[0]])
while q:
r, c = q.popleft()
for dr, dc in ((-1, 0), (1, 0), (0, -1), (0, 1)):
nr, nc = r + dr, c + dc
if (0 <= nr < N and 0 <= nc < N
and g[nr][nc] == 0
and (nr, nc) not in seen_w):
seen_w.add((nr, nc))
q.append((nr, nc))
return len(seen_w) == len(whites)
total = 0
for mask in range(1 << M):
g = [[0] * N for _ in range(N)]
for i in range(M):
if (mask >> i) & 1:
for r, c in orbits[i]:
g[r][c] = 1
if valid(g):
total += 1
return total
for N in (3, 5, 7):
print(f"N={N}: {count_grids(N)} valid grids")
The script prints (the empty all-white grid), , . The value matches Laurent Lessard’s published count and confirms the encoding; larger are handled by the same code (a faster dynamic-programming variant is needed past ).