Skip to content

Instantly share code, notes, and snippets.

@shieldsd
Created April 18, 2012 13:57
Show Gist options
  • Save shieldsd/2413747 to your computer and use it in GitHub Desktop.
Save shieldsd/2413747 to your computer and use it in GitHub Desktop.
Project Euler #44
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