Created
March 16, 2012 09:53
-
-
Save shieldsd/2049329 to your computer and use it in GitHub Desktop.
Project Euler #12
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 count | |
from itertools import dropwhile | |
from math import sqrt | |
def factorise(n): | |
c = 0 | |
sr = int(sqrt(n)) | |
for i in range(1, sr + 1): | |
if n % i == 0: | |
c += 2 | |
if sr * sr == n: | |
c -= 1 | |
return c | |
def triangle(n): | |
return ((n + 1) * n) / 2 | |
print dropwhile(lambda n: factorise(n) <= 500, | |
(triangle(i) for i in count())).next() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment