<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Four Letters Wide]]></title><description><![CDATA[Four Letters Wide]]></description><link>https://fourletterswide.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 18 Nov 2026 14:33:15 GMT</lastBuildDate><atom:link href="https://fourletterswide.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[I Wrote a Word Ladder Solver, and It Humiliated Me]]></title><description><![CDATA[Building a word ladder solver teaches hard lessons about graph modeling, dictionaries, and why shortest path is not the same as fun.]]></description><link>https://fourletterswide.hashnode.dev/i-wrote-a-word-ladder-solver-and-it-humiliated-me</link><guid isPermaLink="true">https://fourletterswide.hashnode.dev/i-wrote-a-word-ladder-solver-and-it-humiliated-me</guid><category><![CDATA[Side Projects]]></category><dc:creator><![CDATA[Toby Marsh]]></dc:creator><pubDate>Tue, 17 Nov 2026 11:25:12 GMT</pubDate><content:encoded><![CDATA[<p>A word ladder, for anyone who has not met one, is the oldest clean puzzle in English: turn WARM into COLD one letter at a time, and every rung in between has to be a real word. WARM, WARD, CARD, CORD, COLD. Done in four moves. It was invented by Lewis Carroll on Christmas Day 1877 for two bored children, which means the puzzle is old enough to have outlived the light bulb's novelty.</p>
<p>When I finally sat down to write a solver for it a few months ago, I estimated twenty minutes. I have taught breadth-first search. I have whiteboarded it for interviews. A word ladder is a textbook shortest-path problem — words are nodes, one-letter differences are edges, BFS gives you the shortest ladder. What could go wrong?</p>
<p>Three separate humblings, as it turned out. Let me walk you through them, because each one is a lesson about modeling that no amount of algorithm practice had taught me.</p>
<h2>Humbling number one: the naive neighbor search</h2>
<p>My first version held the dictionary in a list and, for each word under consideration, compared it against all N words to find one-letter differences. Classic O(N × L) per step, times N steps, times the branching factor. With a proper dictionary of common five-letter English words, this was not fatal. It was just embarrassing — thousands of string comparisons to discover that HOUSE and MOUSE are neighbors.</p>
<p>The fix is one of my favorite tricks in all of programming, precisely because it is so cheap. For each word, generate its wildcard patterns — <em>OUSE, H</em>USE, HO<em>SE, HOU</em>E, HOUS* — and index the dictionary into buckets keyed by those patterns. Words that share a pattern are automatically neighbors. You build the adjacency structure once, in linear time, and every lookup after that is a dictionary access. This is the same family of trick as grouping anagrams by sorted letters. It converts a search problem into a hash problem, and it is the moment my solver stopped being a toy.</p>
<p>(If you want to see this idea executed at serious scale, look up Donald Knuth's Stanford GraphBase. Knuth built a graph of 5,757 common five-letter English words — the file is still on his Stanford page as sgb-words.txt — with edges between one-letter-different pairs, and wrote an interactive ladders program around it decades ago. The graph is mostly one giant connected blob, with a handful of unlucky isolated words that have no neighbors at all. More on that in a moment.)</p>
<h2>Humbling number two: the dictionary is the problem</h2>
<p>BFS is provably optimal for shortest paths. Nothing else in the system is optimal, because the dictionary is a judgment call. Is ADZE a fair rung? Is a plural acceptable? A Scrabble tournament dictionary and a children's puzzle page will answer differently, and both answers are correct for their context.</p>
<p>My solver, using a tournament-grade word list, kept producing ladders that were technically valid and emotionally wrong — gleeful chains through words nobody has spoken since a tax roll in 1840. A human puzzle editor curates for fairness; my code curated for coverage. I ended up hand-pruning the list and losing about nine percent of it, and my solver's ladders immediately got more pleasant. The uncomfortable takeaway: the algorithm was never the product. The data curation was.</p>
<p>This is also why I now extend genuine sympathy to anyone who runs a daily word puzzle. Try <a href="https://poopleunlimitedfun.org/">Poople Unlimited</a> on a random morning and you will feel the editorial hand immediately — the day's ladder is solvable, the rungs are words you actually know, and the difficulty breathes from day to day instead of spiking randomly. That is curation work, invisible until it is missing.</p>
<h2>Humbling number three: shortest is not the same as satisfying</h2>
<p>The final humbling was philosophical. Once the solver worked, I fed it the day's puzzle from my morning routine, got the four-step answer in under a second, and felt absolutely nothing. Because of course. The pleasure of a word ladder was never the answer — it is the little collapses of dead ends, the moment you back out of a vowel corner and see the path you missed. My solver had optimized the fun out of the game with the same motion that optimized the runtime.</p>
<p>I kept both habits, and they now feed each other. The solver is my sandbox for graph ideas: I have since added bidirectional search, which searches from both ends and meets in the middle, and played with an A* variant whose heuristic is the count of differing letters between the current word and the target. Both are lovely small exercises — each one is an afternoon, each one teaches you a different trade-off between setup cost and query speed. The daily hand-solved puzzle is my sanity check that the game is still a game.</p>
<h2>What I would tell past me</h2>
<p>If you have a spare evening, I genuinely recommend building one of these, in whatever language you are currently least rusty in. Not for the résumé line — nobody is impressed by LeetCode problem 127 — but for the three moments when the obvious model is wrong and you get to feel the problem push back. The wildcard bucketing trick alone is worth the evening. And when you are done, run your solver on Knuth's 5,757 words and go looking for the isolated islands, the words with no neighbors at all. There is something quietly funny about a word like ALDOL sitting alone in the corner of a graph with 5,757 vertices, linguistically real and completely unreachable by ladder.</p>
<p>Then close the laptop, pour a coffee, and solve one by hand the slow way. The Victorians had it right: the point was never the shortest path. The point was the walk.</p>
]]></content:encoded></item></channel></rss>