Dev.to WebDev 🛠 Dev 👁 0 📖 1 min read

Validating Shortest Routes Without a Backend

A daily puzzle site has one hard correctness problem: the advertised answer must be real. If the published route is not valid, or the par is not the shortest known route, players will find out within an hour. The interes

A daily puzzle site has one hard correctness problem: the advertised answer must be real. If the published route is not valid, or the par is not the shortest known route, players will find out within an hour. The interesting engineering question is how to verify both properties cheaply, ideally without a backend.

The validity check is cheap. Given a route as a list of words, assert that every consecutive pair differs by exactly one letter and that every word exists in the curated set. That is O(n) in route length and can run in the browser, in a build step, or in a test. There is no reason to ever publish an invalid route.

The shortest-path check is the expensive one, and the trade-off is between precomputation and runtime. Precomputing all pairs is O(n^2) and unnecessary for a game that needs one pair per day. A breadth-first search from the start, bounded by the budget, is fast enough on a curated set of a few thousand four-letter words. Bounding the search is what makes it a verification step rather than a planning problem: you only need to know whether a shorter route exists, not what it is.

The subtle bug is determinism. If the word list changes between the day a route is published and the day a player checks it, the answer page and the game disagree. Versioning the word list per puzzle date fixes that, and it also makes old answer pages reproducible.

The last piece is caching. A static site can ship the puzzle and the verified route as JSON, with the validator run in CI before deploy. If CI fails, the puzzle is never published. That is a small amount of process that buys a large amount of trust.

How the game works documents the rules the validator enforces, and the solver is the player-facing version of the same search.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.