SEND + MORE = MONEY
MOSCOW = RED ** 2
ONE + TWO + TWO + THREE + THREE = ELEVEN
COUPLE + COUPLE = QUARTET

Each of these can be turned into a valid arithmetic expression by figuring out a mapping from the letter of the words to the digits 0-9. Remember that 0 can’t start a number! These puzzles are fun, but it turns out to be easier to just solve all of them in one fell swoop.

In an effort to do exactly that, I wrote a solver that is extremely general at the cost of being extremely slow. Why is it so slow? Because I avoided parsing the equations and just used eval(). This does mean that any operation on integers that python supports – bit shifting, XOR, +, **, //, are all usable.

The solver is slow, but there are only at most 10! = 3,628,800 combinations to consider, so despite its stupidity and the slowness of eval() it runs in under a minute on most processors.

If I recall correctly, the first version of this code was written in a race with a fellow geek. He was using math and logic to solve the problem “SEND+MORE=MONEY” by hand, and I was writing the stupid solver.

Here is the code (cleaned up and generalized)
Here is a nice list of cryptarithm puzzles.