Index ¦ Archives ¦ Atom ¦ RSS

Word arithmetic puzzle generator

I was digging through some old code of mine when I came across this script. To me, this script was a demonstration of the beauty and elegance of the python language.

You might have come across a puzzle like this: AID + ICED = IDEA. What digits would you assign to the characters A,C,D,E,I so that the arithmetic will work? The answer is A=0, C=4, D=5, E=1, I=2.

The “word arithmetic” script can generate such puzzles given a word list and characters. Here is the code and a sample word list.

Running the script:

python word_arithmetic.py --words-file words --letters AEIBCDFGHI

In the command above you are asking the script to generate word combinations where A=0, E=1, I=2, B=3 and so on.

Sample output

letters = A=0, E=1, I=2, B=3, C=4, D=5, F=6, G=7, H=8, I=9
FEE + AHA = FIE
DACCA + BEEBE = HEDGE
ACHED + AHA = CHID
BIG + BAH = GAD
BIB + ACED = HAH
DADA + HIE = DICE
BIG + CAF = AHAB
ABB + CHE = DEC
AID + ICED = IDEA
...
...

© Prashanth Ellina. Built using Pelican. Theme by Giulio Fidente on github.