Created
April 20, 2012 15:48
-
-
Save shieldsd/2429836 to your computer and use it in GitHub Desktop.
Project Euler #46
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 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