Created
June 4, 2015 23:12
-
-
Save mkowoods/124e5fcf1d4ce141df5d to your computer and use it in GitHub Desktop.
Quick Solution to Cryptarithmetic with generators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
equation = 'ODD + ODD == EVEN' | |
translator = (string.maketrans('ODEVN', str(o)+str(d)+str(e)+str(v)+str(n)) | |
for o in range(10) | |
for d in range(10) | |
for e in range(10) | |
for v in range(10) | |
for n in range(10) | |
if len(set([o, d, e, v, n])) == 5 | |
if o != 0 and e != 0 | |
) | |
for trans in translator: | |
numerical_eq = equation.translate(trans) | |
if eval(numerical_eq): | |
print numerical_eq | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment