Solve the Jumble

October 4, 2022 - Reading time: 3 minutes

In the "Jumble" puzzles (copyrighted by David L. Hoyt) the challenge is to unscramble a set of words.  The individual words are usually 5 to 8 characters long. In the official puzzle, selected letters from the individual answers are unscramble to provide the punchline to a horrific pun.

How to Solve It

This is not hard to solve.  Usually the answer pops right into your head after a quick glance. Sometimes it doesn't work and you need tricks to jump-start the puzzle-solving process (like reversing the scrambled letters, or looking for common groupings ... 'th', 'ing', 'er', etc.)

It is a fun Comp Sci 101 exercise, because people can be very creative at finding difficult solutions. On the other hand, you can use a clever hack described by Jon Bentley in the "Aha! Algorithms" essay from his book "Programming Pearls".

To unscramble a word, use this central trick: sort the letters of the scrambled word into alphabetical order, then compare this sorted arrangement of letters with a dictionary of words processed the same way ... an alphabetical list of words each paired with a version of itself with its letters sorted alphabetically.

For example, say that one of our scrambled puzzle words is "lorac". Sort the letters into alphabetical order to obtain "aclor". Then search the dictionary for any five-letter words whose letters also sort to "aclor". (I used a list of about 100,000 words and found four solutions: "calor", "carlo", "carol", and "coral")

The final script used in this page is written in PHP.  The word list and sorted counterparts are kept in a SQLite table, which facilitates the function used to solve the puzzle.  Bentley's version only required a text file (no SQL), adding a step to process the list of words and sorted aliases into a 'compressed' file: each line of the file starts with a unique 'sorted' key, followed by all of the words that share that key, separated by spaces.

You can try it out on the Puzzle Solver page, right here.

I set up a GitHub repository with most of the essential code (PHP/HTML and Python versions of the solver, and a Python script to create the SQLite word table) here: https://github.com/vandinem/jumble


Mark's Blog
(for www.vandine.biz)

Charles the Foolish (by Al Van Dine)
mark.vandine on gmail
vandinem on Twitter