Created
April 18, 2012 13:58
-
-
Save shieldsd/2413753 to your computer and use it in GitHub Desktop.
Project Euler #45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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