Skip to content
Vamshi Jandhyala

Books · The Riddler

Chapter 37

Can You Solve The Vexing Vexillology Of Spelling Bee?

The Riddler for January 3, 2020. The Express is a visual identification puzzle: three national flags whose pixels have been scrambled, to be matched to their countries. With only the colour histograms and no way to reproduce the scrambled images here, it is an image-dependent puzzle and we defer it. The Classic optimises the New York Times Spelling Bee honeycomb.

Riddler Express

Each of three images is a different nation’s flag whose pixels have been randomly rearranged. From the scrambled images alone (the colours and their proportions are preserved, the arrangement is destroyed), identify which flag is which.

The Riddler, FiveThirtyEight, January 3, 2020(original post)

Deferred (image-only)

This puzzle cannot be solved from the text. Scrambling the pixels keeps only each flag’s colour histogram, so the entire content of the question lives in the three bitmap images: the solver inspects the proportions of each colour and matches them to a flag whose colours appear in those proportions. There is no statement to encode and no derivation to carry out; without the original images (which we cannot faithfully reproduce here), there is nothing to compute. We defer it for the same reason as the other image-only Riddlers in this collection.

Riddler Classic

In the New York Times game Spelling Bee, seven letters sit in a honeycomb with one in the center. A valid word is at least four letters long, includes the center letter, and uses only the seven given letters (repeats allowed). A four-letter word scores 11 point; a longer word scores its length; a pangram that uses all seven letters scores 77 bonus points on top. Which seven-letter honeycomb gives the highest possible total score? The seven letters must be distinct, must not include S, and must admit at least one pangram. Score against the enable1 word list.

The Riddler, FiveThirtyEight, January 3, 2020(original post)

Solution

A word’s eligibility depends only on its set of distinct letters: it counts for a honeycomb when that set is contained in the seven letters and includes the center. So group the whole dictionary by letter-set, summing the scores of all words sharing each set. A honeycomb is then scored by adding up the group scores of every letter-set that fits inside its seven letters and contains its center.

Only honeycombs with at least one pangram are allowed, so the candidate seven-letter sets are exactly the letter-sets of the pangram words. For each such set there are seven choices of center; scoring all of them and taking the best gives a clear winner. The highest-scoring honeycomb is the letters {A,E,G,I,N,R,T} centered on R,\boxed{\{A,E,G,I,N,R,T\}\ \text{centered on } R}, worth 3898\boxed{3898} points. Its richness comes from the enormous family of words built on the -ing, -er and re- fragments those letters supply.

The computation

Load enable1, keep words of length 4\ge 4 with no S and at most seven distinct letters, and total the scores within each letter-set. Take the candidate seven-letter sets from the pangrams; for each set and each center, sum the group scores of the subsets that contain the center, and report the maximum.

import urllib.request
from collections import defaultdict
url = "https://norvig.com/ngrams/enable1.txt"
words = [w.decode().strip() for w in urllib.request.urlopen(url)]
def score(w):
    pangram = 7 if len(set(w)) == 7 else 0
    return 1 if len(w) == 4 else len(w) + pangram
group = defaultdict(int)                  # score by letter-set
for w in words:
    if len(w) >= 4 and 's' not in w and len(set(w)) <= 7:
        group[frozenset(w)] += score(w)
pangrams = [s for s in group if len(s) == 7]
best = (0, None)
for L in pangrams:
    subs = [(s, sc) for s, sc in group.items() if s <= L]
    for center in L:
        total = sum(sc for s, sc in subs if center in s)
        best = max(best, (total, (center, "".join(sorted(L)))))
print(best)                                     # (3898, ('r', 'aeginrt'))