Skip to content

Instantly share code, notes, and snippets.

@rdmarsh
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdmarsh/f29a235a0b692494e2ff to your computer and use it in GitHub Desktop.
Save rdmarsh/f29a235a0b692494e2ff to your computer and use it in GitHub Desktop.
if "tent+ent=rares", what's "near"? Each letter is a digit, assume base 10
-------------
tent : 7527
ent : 527
rares : 08054
near : 2580
-------------
tent : 8528
ent : 528
rares : 09056
near : 2590
-------------
tent : 9579
ent : 579
rares : 10158
near : 7501
-------------
#!/usr/bin/python
#if "tent+ent=rares", what's "near"?
#each letter is a digit, assume base 10
#0 1 2 3 4 5 6 7 8 9
start=0
end=10 #ranges don't include the last value
print "-------------"
t_list = range(start, end)
for t in t_list:
e_list = range(start, end)
e_list.remove(t)
for e in e_list:
n_list = range(start, end)
n_list.remove(t)
n_list.remove(e)
for n in n_list:
r_list = range(start, end)
r_list.remove(t)
r_list.remove(e)
r_list.remove(n)
for r in r_list:
a_list = range(start, end)
a_list.remove(t)
a_list.remove(e)
a_list.remove(n)
a_list.remove(r)
for a in a_list:
s_list = range(start, end)
s_list.remove(t)
s_list.remove(e)
s_list.remove(n)
s_list.remove(r)
s_list.remove(a)
for s in s_list:
tent_s = str(t) + str(e) + str(n) + str(t)
ent_s = str(e) + str(n) + str(t)
rares_s = str(r) + str(a) + str(r) + str(e) + str(s)
tent_i = int(tent_s)
ent_i = int(ent_s)
rares_i = int(rares_s)
if tent_i + ent_i == rares_i:
near_s = str(n) + str(e) + str(a) + str(r)
near_i = int(near_s)
print " tent : %5s" % tent_s
print " ent : %5s" % ent_s
print "rares : %5s" % rares_s
print " near : %5s" % near_s
print "-------------"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment