One of the goals of creating this blog was to show you some cool math stuff you might not have seen before. So I thought I’d create a puzzle about this:

Day005Crypt1Just replace each letter with a digit from 0–9 so that the sum is correct. No number begins with a 0. One more thing: M + T = A. Good luck!

Perhaps you’ve never seen puzzles like this before — they’re called cryptarithms. At first they look impossible to solve — almost any assignment of numbers to letters seems possible. But not really. You’re welcome to try on your own first — but feel free to read on for some helpful advice.

Look at the last column (the units). If L + H + G ends in H, then L + G must end in a 0. Since L and G are digits, then L + G = 10. This doesn’t completely determine L or G, but once you know one of the numbers, you know the other.

As a result, you also know there’s a carry over to the third column (tens). What does this mean? That 1 + O + T + O ends in C. Since O + O is an even number, this means that if T is even, then C is odd, and if T is odd, then C is even. We even know a bit more about T from looking at the sum: T is either 1 or 2, since adding three numbers less than 10,000 gives a sum less than 30,000.

What about the second column? O + A + L ends in A. We might be tempted to think that O + L must end in a 0, but that would mean that O + L is 10. This can’t be, since that would mean that G = O (remember that L + G = 10). Therefore there has to be a carry from the third column over to the second column, meaning O + L = 9. So O is one less than G.

Get the idea? There’s a lot of information you can figure out by looking at the structure of the letters in the sum. But it turns out that without the condition M + T = A, there are 12 solutions to this puzzle! Multiple solutions must occur here, for if you can solve this puzzle, you can also solve

Day005Crypt2The M and B occur just once, and at the beginning of numbers. This means if M = 7 and B = 9 in a solution, then putting M = 9 and B = 7 — with all other letters staying the same — will also produce a solution. In looking at all the solutions, I found that giving M + T = A results in a unique solution without giving values for specific letters.

That’s all the help you get! Sometimes you might just guess well and stumble onto a solution — but take the additional challenge and prove you’ve got the only solution to the cryptarithm.

How do you create a cryptarithm? There was a time I did so by hand — but those days are gone. Read more if you’d like to see how you can use programming to help you create these neat puzzles.  (Of course there are online cryptarithm solvers, but that takes all the fun out of it!)

How would you write a program to create a cryptarithm? Bascially, you’ve got to test every way of assigning numbers to letters. If you assigned the numbers 1, 2, and 3 to A, B, and C, then ABC could be 123, 132, 213, 231, 312, or 321. These are called permutations of the list of numbers 123. We know that if you have n numbers, there are n! possible permutations of these n numbers — and this grows very quickly.

In my cryptarithm, there are 10 letters: C, O, L, M, A, T, H, B, G, and E. Using 10 digits gives 3,628,800 possible permutations. And unless you know some information in advance — such as relationships about certain letters — and program them into your routine, you’ve got to test every one.  For example, you can test to see that no word begins with a 0 — more code to write, and perhaps a little more efficient.  There is often such a trade-off:  simpler code may run a bit longer, and you’ve got to decide if the extra work programming is worth the increase in efficiency.  No easy answer to this one….

I used software called Mathematica to create this cryptarithm. But to show you how to make your own in Python, we’re going to create a cryptarithm where no letter stands for 0. This is because to use the online version, you’d have to wait forever for the program to run. When you see the code, though, you’ll be able to adapt it to all ten digits if you run Python on your own computer.

To make sure we only have nine letters, let’s try to create the cryptarithm

Day005Crypt3You can follow along with the Python code here.

What makes this especially easy is that creating all the permutations of a list is built into Python. If you had to program this aspect yourself — well, this would definitely be the hardest part. Instead, we’ll just use the built-in Permutations function.

Next comes the test function. It’s pretty self-explanatory — you can assign multiple variables at one time. You then just print out every time the sum comes out right.

Finally, we check each permutation. I used “list comprehension” here — in case you want to look that up and learn more about Python programming. (There are similar constructs in other programming languages as well — maps in LISP, and the “/@” construct in Mathematica.) I always prefer this to a for or while loop when I can get away with it.

So it looks like there are eight possible solutions just using the digits 1–9. There’s only one solution where C + L = O, or when L + M = A, for example. Maybe you might find another clue which you prefer.

Now you can create your own puzzles and share them with others. The best puzzles — in my opinion — are those where you don’t have to give any additional clues. These take more effort, but they’re possible. Here’s one for you which has a unique solution:


And when you create your own puzzle, post it as a comment!  I’m sure many other readers would like some neat problems to solve, too.

Published by

Vince Matsko

Mathematician, educator, consultant, artist, puzzle designer, programmer, blogger, etc., etc. @cre8math

3 thoughts on “Cryptarithms”

  1. Nice problem! I was able to work it out by hand with a little trial and error. First, you see that M must be 9. After that, you can figure out that L = R + 1, and then N = L + 1. At this point, you have enough information to make the number of cases manageable.

    How did you come up with this cryptarithm?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s