Skip to content

Instantly share code, notes, and snippets.

@adrientetar
Created September 17, 2013 15:02
Show Gist options
  • Select an option

  • Save adrientetar/6595564 to your computer and use it in GitHub Desktop.

Select an option

Save adrientetar/6595564 to your computer and use it in GitHub Desktop.
Project Euler #12 in Python.
#!/usr/bin/env python
#
# Copyright (C) 2013, Adrien Tétar. All Rights Reserved.
#
def triangleNumber(rank):
res = 0
for i in range(1, rank+1):
res += i
return res
def sumFactors(triangle):
res = 1 # t%1=0
for i in range(2, triangle+1):
if (triangle%i == 0):
res += 1
return res
cur = 0
while (sumFactors(triangleNumber(cur)) <= 500):
cur += 1
print(triangleNumber(cur))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment