Created
April 18, 2012 13:57
-
-
Save shieldsd/2413747 to your computer and use it in GitHub Desktop.
Project Euler #44
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 count | |
from itertools import islice | |
def f(n): return n * (3 * n - 1) / 2 # nth pentagonal | |
def p(n): return not ((sqrt(24 * n + 1) + 1) / 6) % 1 # is pentagonal | |
print islice((abs(f(i) - f(j)) | |
for i in count(2) | |
for j in xrange(i - 1, 1, -1) | |
if p(f(i) + f(j)) | |
and p(abs(f(i) - f(j)))), 1).next() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment