Skip to content

Instantly share code, notes, and snippets.

@tmc
Created May 26, 2009 01:31
Show Gist options
  • Save tmc/117837 to your computer and use it in GitHub Desktop.
Save tmc/117837 to your computer and use it in GitHub Desktop.
def isinteger(n):
return n == int(n)
def divisors(n):
result = []
for x in xrange(1, n+1):
if isinteger(n / (x + 0.0)):
result.append(x)
return result
def num_divisors(n):
return len(divisors(n))
def triangle_numbers(n=False):
x = i = 0
while n == False or i < n:
i += 1
x += i
yield x
if __name__ == '__main__':
nd = num_divisors(1)
tn = triangle_numbers()
lastmax = 0
while nd <= 500:
n = tn.next()
nd = num_divisors(n)
if nd > lastmax:
lastmax = nd
print n, '\t', nd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment