11 nanoseconds per word: Ridiculously Over-Optimizing Anagrams

David G. Andersen October 27, 2026

BLOG → BLOT → SLOT → SPOT ↝ POST

A friend recently pointed out a new Word Ladder game variant: Find a path of mutations from a start word to an end word, where mutations can be single letter changes, single letter deletions or additions, or anagramming the word. It annoyed me (the paths involving anagrams can be wickedly hard to spot), so, naturally, I wrote a solver for it. And when the solver took over a second to run, I of course had to optimize it. Along the way, I found a fun trick for anagram indexing—fitting a collision-free prime-product identifier for every word in the dictionary into a single 64-bit integer—that I hadn't seen before (though the history of computing is long and Knuth probably noticed it in 1965).