traviscline (owner)

Revisions

gist: 117837 Download_button fork
public
Public Clone URL: git://gist.github.com/117837.git
Embed All Files: show embed
Python #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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