Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created December 9, 2011 17:36
Show Gist options
  • Select an option

  • Save jakedobkin/1452516 to your computer and use it in GitHub Desktop.

Select an option

Save jakedobkin/1452516 to your computer and use it in GitHub Desktop.
Euler 45 in Python
# we'll store numbers in two sets and keep going until we get a match
i = 286
found = False
p = set()
h = set()
while found == False:
hex = (i*(2*i-1))
h.add(hex)
pent = (i*(3*i-1))/2
p.add(pent)
tri = (i*(i+1))/2
if tri in h and tri in p:
print i,tri, "found!"
found = True
i = i + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment