Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

why is my solution so mega slow

Name: Anonymous 2013-05-01 11:27

Find highly divisible triangular number.

import math
maxdivisor = 500
n = 1
while True:
    #print(list(getfactors(triangle)))
    sn = (n**2 + n) / 2
    counter = 0
    i = int(math.sqrt(sn))
    while i >= 1:
        if sn % i == 0:
            counter += 1
        i -= 1
    lenfactors = counter + 1
    #print(triangle, lenfactors)
    if lenfactors > maxdivisor:
        print(sn, lenfactors)
        sys.exit(0)
    n += 1

Name: Anonymous 2013-05-01 16:55

my ruby solution takes 1 second and is just 2 lines
it's euler 12 btw

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List