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
...
...
Tags: programming, puzzle, python, word arithmetic















Andrea Sender wrote,
I’ve been wishing I knew enough programing to generate the “Word Arithmetic” puzzles I love to solve. They are Long Division problems, where the numerals 0-9 are replaced by letters such that a word devided by another word results in a third word. The rest of the letters needn’t form words except that when the puzzle is solved the letters arranged 0-9 make a word or a phrase.
I can make them myself, but only by using much trial and error which a computor would be able to do better and faster. I only know a little basic which is not enough to write the code though I see how it can be written. Would you be intested in writing such a program?
Sincerely yours,
Andrea Sender
Link | January 25th, 2009 at 9:57 pm
DARCEL DAVENGER wrote,
0 1 2 3 4 5 6 7 8 9
WHITTLE/HALT = TIE
HOW DO I SOLVE THIS USING WORD ARITHMETHIC: DIVISION
Link | August 25th, 2009 at 7:20 am