Skip to content

Instantly share code, notes, and snippets.

@shieldsd
Created March 16, 2012 09:53
Show Gist options
  • Save shieldsd/2049329 to your computer and use it in GitHub Desktop.
Save shieldsd/2049329 to your computer and use it in GitHub Desktop.
Project Euler #12
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