Skip to content

Instantly share code, notes, and snippets.

@Radcliffe
Created March 9, 2016 23:34
Show Gist options
  • Save Radcliffe/43bbb0efc3ca6c3db535 to your computer and use it in GitHub Desktop.
Save Radcliffe/43bbb0efc3ca6c3db535 to your computer and use it in GitHub Desktop.
Cryptarithm: HALF + FIFTH + TENTH + TENTH + TENTH = WHOLE
import itertools
for a,e,f,h,i,l,t,n,o,w in itertools.permutations(range(10)):
if h > 0 and t > 0 and f > 0 and w > 0:
half = 1000*h + 100*a + 10*l + f
fifth = 10100*f + i*1000 + t*10 + h
tenth = 10010*t + 1000*e + n*100 + h
whole = w*10000 + h*1000 + o*100 + l*10 + e
if half + fifth + 3*tenth == whole:
print "%s + %s + %s + %s + %s = %s" % (
half, fifth, tenth, tenth, tenth, whole)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment