How to stop students guessing the answer
11 October 2026 · About The Ritz Affair
Give students a database and a question with a single answer, and some of them will find that answer without writing the query you had in mind. Not out of dishonesty, usually, but because people take the shortest path they can see. A puzzle that can be solved by a shortcut teaches the shortcut.
Building The Ritz Affair, a detective game played in SQL, meant closing those shortcuts one by one. This article lists the ones that come up most often, and the techniques that close them. They apply to any SQL exercise with a single expected answer, story or not.
The usual shortcuts
Before a chapter ships, it is tried the way an impatient student would try it. Five families of shortcut cover almost everything.
- What they already know. Earlier answers, names in the story, details on a character card. If the text says who the suspect is, no query is needed.
- Keyword search. A LIKE on every interesting word in the question: the victim's name, the object, the place. If the right row is the only one that mentions the jewel, the search finds it.
- The obvious filter. One or two conditions taken straight from the question, then eyeballing the result. A short list, an unusual value or a lone row stands out.
- The plausible guess. The most valuable item is the one that was stolen; the person who appears most often is the one to watch. If the plausible guess is right, the query was decoration.
- Ignoring the construct. A chapter about window functions that can be solved with a plain ORDER BY has not taught window functions.
There is also a family specific to databases: the data's own structure. Planted rows are often added last, so they have the highest ids, and ORDER BY id DESC LIMIT 1 finds them. Or they are added in one batch, so their ids sit together in a range. Or they are the only rows with a particular empty value.
Turn every shortcut into a decoy
The fix is the same each time: when a shortcut leads to the answer, add data that makes it lead somewhere else. If a keyword search finds the right report, add other reports that use the same word. If the most valuable item is the answer, add more valuable ones that nobody touched. If the busiest name is the culprit, give some innocent bystanders even more entries.
Good decoys are boring. A decoy that is obviously planted is just another clue. The best ones look like ordinary rows that happen to match the naive query, so that the student who stops early finds a confident, wrong answer, and the student who reads the question carefully finds the right one.
The plot's own rows need the same treatment. In The Ritz Affair the database is generated by a script, and after the evidence is written, each planted row swaps its id with a random ordinary row. Sorting by id, or reading a range of ids, shows nothing special. Missing values are spread across the noise in the same proportion as in the plot, so IS NULL singles nothing out either.
Make the decoys permanent
Decoys have a weakness: they are fragile. Change the story, regenerate the data, adjust a value, and a decoy that used to bite may quietly stop doing so. Nobody notices until a student solves the chapter in one line.
The answer is to treat shortcuts like bugs, with tests. Each chapter carries, next to its solution, a list of the shortcuts found so far, written as queries. Every time the database is built, the script runs them all:
- the solution must return exactly the answer, nothing more;
- each shortcut query must not return the answer;
- each clue a chapter relies on must still be findable by the queries meant to find it.
If any of these fails, the build stops. A shortcut found once stays closed for good, and the list grows each time a new one is found, the way a test suite grows with each bug fixed.
Check the answer, hide the answer
A game that checks answers in the browser has to keep them out of the page. The Ritz Affair ships only a fingerprint of each answer, a SHA-256 hash of a normalised form. When a student types an answer, the page normalises it the same way, hashes it and compares. Reading the page's source reveals nothing usable.
Normalisation is what makes this pleasant to use. Case, punctuation, titles and extra words are stripped before hashing, so "Mr Smith", "smith" and "SMITH." count as the same answer. The rules have to be identical in the generator and in the page, so a fixed list of test inputs is checked on both sides.
This is not a defence against a determined attacker: with a small set of plausible answers, anyone can hash them all and compare. It is a defence against the casual look at the page source, which is the one that actually happens in a classroom.
Keep it a game
Even with every shortcut closed, a puzzle that runs in the student's browser cannot be made cheat-proof. Answers can be shared, and a timed session can be gamed. That is fine, as long as the game is not used as an exam. Its job is to make the honest path the easiest and most interesting one, and to make sure that a student who follows it has used the construct the lesson is about.
The habit that matters most is the first one: before a puzzle ships, try to solve it badly. Every time a lazy query finds the answer, there is a decoy to write.