DataGenetics

Cryptogram Puzzle

A cryptogram is a mathematical puzzle in which various symbols or letters are used to represent numeric digits, typically in the form of a sum or equation.

Each distinct symbol is used to represent a distinct number in the puzzle. The job of the puzzle solver is to work out which letters correspond to which numbers.

Recently I shared the following cryptogram on my Facebook feed as a “coffee time challenge”. I thought it was fun little puzzle because there is a unique solution. In the puzzle below, each of the letters A-I represents a distinct digit 1-9.

Though I thought my instructions were clear, a colleague misinterpreted the question and ended up answering a similar, but subtly different, cryptogram in which he assumed the letters in the denominators represented single digits that were multiplied together.

Credit to my friend; he came up with a correct answer to his version of the puzzle!

What I find interesting is that there is only one solution to this different puzzle too (ignoring the trivial rotations and rearrangements).

If you want to give it a go yourself, grab a piece of paper and a cup of coffee.

Once you think you have an answer to either puzzle (or you’ve just given up), click on the button below to reveal the answers.

Show me the answers

Answers

Here are the answers:

Answer 1

If we assume the letters represent digits, here is the only solution:

Answer 2

If we assume the letters represent coefficients, here is the only solution:.

Solving

There are a variety of tools that can be employed to solve cryptograms, just like there are lots of techniques that can be used to solve puzzles like Sudoku. These include: Algebraic tehniques, number theoory, factorization, digital roots, elimination, carries, divisibility rules, modular arithmetic, the Chinese Remainder Theorem, and even simple trial and error.

I have to confess that, when I saw the puzzle, I adopted the lazy technique of simply brute forcing it and trying every possible combination of numbers!

As we know that each of the nine letters is distinct, the number of permuations is just 9 factiorial. This is a very manegable 362,880 equations to test. As the brute force approach will try every possible combination of digits, this will mean that this approach will find all possible solutions.

Many programming languages now have built in commands to generate permutations and combinations. The language I was using did not, so I went back to first principles. The code to generate permutations is not very complicated (especially if you are comfortable with recursion). For our puzzle there are nine possible letters, and nine digits. There are nine possible values the first letter can be, and once this is selected, there are eight possible for the next digit, and seven for the next … You can see how we just have to loop through: 9 × 8 × 7 × 6 × … × 2 × 1 = 9! permutations.

The number of permutations is, of course, fixed at 362,880 but the ordering they appear can be very different from row to row depending on the technique we use to generate them. There is an very clever algorithm for generating permutations, called Heap's Algorithm. This is named after the creator B.R. Heap, who first proposed it in 1963 (This should not be confused with Heapsort which was invented, but not named after, J.W.J. Williams the following year).

What is really clever about the Heap algorithm for generating permutations is that each subsequent permutation differs from the previous perumation by the simple switching of a pair of values! In an analogous way to Gray Code, the number of number of swaps needed to transition from each row to the next is small.

The Heap algorithm can be implemented recursively, or non-recursively, and, because each subsquestion row simply switches two values, the algorithm is perfectly efficient with amount of swapping that needs to occur.

An example of the algorithm in use is displayed on the right to show how it generates the 24 possible permutations for four numbers. The algorithm starts out at the top with 1234 and ends with 2341. If you look at each row you will see that two numbers stay the same, and two change.