Skip to content

Instantly share code, notes, and snippets.

@shieldsd
Created April 18, 2012 13:58
Show Gist options
  • Save shieldsd/2413753 to your computer and use it in GitHub Desktop.
Save shieldsd/2413753 to your computer and use it in GitHub Desktop.
Project Euler #45
from math import sqrt
from itertools import islice
from itertools import count
def pentagonal(n):
return not ((sqrt(24 * n + 1) + 1) / 6) % 1
def hexagonal(n):
return not ((sqrt(8 * n + 1) + 1) / 4) % 1
def triangle(n):
return ((n + 1) * n) / 2
print islice((triangle(n) for n in count(285 + 1)
if pentagonal(triangle(n))
and hexagonal(triangle(n))), 1).next()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment