Skip to content

Instantly share code, notes, and snippets.

@shieldsd
Created April 20, 2012 15:48
Show Gist options
  • Save shieldsd/2429836 to your computer and use it in GitHub Desktop.
Save shieldsd/2429836 to your computer and use it in GitHub Desktop.
Project Euler #46
from itertools import takewhile, count, imap
from math import sqrt
from operator import and_
def twicesq(n):
return takewhile(lambda x: x < n,
(x * x * 2 for x in count(1)))
def isprime(n):
for x in range(2, int(sqrt(n)) + 1):
if n % x == 0:
return 0
return 1
print (i for i in count(1)
if i % 2 != 0 and not isprime(i)
and reduce(and_, imap(lambda b: not isprime(b),
imap(lambda j: i - j,
(j for j in twicesq(i)))), 1)).next()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment