Skip to content

Instantly share code, notes, and snippets.

@yyl
Created June 28, 2012 13:08
Show Gist options
  • Select an option

  • Save yyl/3011271 to your computer and use it in GitHub Desktop.

Select an option

Save yyl/3011271 to your computer and use it in GitHub Desktop.
Euler project 12 triangle number
from math import sqrt, floor
def euler12():
D = 0
n = 1
step = 2
while D < 500:
n += step
step += 1
D = findDivisor(n)
return n
def findDivisor(m):
d = 2
for i in range(2,int(floor(sqrt(m)))):
if m%i == 0:
d += 2
if m/i == i:
d -= 1
return d
if __name__ == '__main__':
print euler12()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment