Skip to content

Instantly share code, notes, and snippets.

@mkowoods
Created June 4, 2015 23:12
Show Gist options
  • Save mkowoods/124e5fcf1d4ce141df5d to your computer and use it in GitHub Desktop.
Save mkowoods/124e5fcf1d4ce141df5d to your computer and use it in GitHub Desktop.
Quick Solution to Cryptarithmetic with generators
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