Kevin Stock

Longest Shortest Word Ladder

Inspired by a statue in the Wellington botanic garden, I wanted to find the two words with the longest shortest path between them. More properly I've learned, the diameter of the graph of words connected by single letter substitutions. For the dictionary I used, the here's the only path of length 13 for six letter words:

BUTLER
BUTTER
BETTER
LETTER
LATTER
MATTER
MASTER
FASTER
FOSTER
POSTER
POSTED
HOSTED
HOSTEL

A first version in python with networkx was too slow, so I had codex write it in rust and implement Floyd-Warshall directly.

Using a word list of the 10000 most common english words, the above was the only path length 13 for 6 letter words. For four letter words there are 50 paths of length 21, and for five letter words there are 13 paths of length 37.

Googling this afterwards, I found there's a pretty old game about this.

I then had codex write an implementation without any guidance from me. It implemented BFS from every word to find the furthest, which ran faster, presumably because it's sparse and there are many disconnected components.


Last updated: