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

Pages: 1-

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 11:33

because it isn't [code]

Name: Anonymous 2013-05-01 14:24

because python

Name: Anonymous 2013-05-01 14:32

Try running sudo apt-get remove python; sudo apt-get install perl

Name: Anonymous 2013-05-01 14:46

apt-get
Why would anyone run that?

Name: Anonymous 2013-05-01 15:04

test

test

Name: Anonymous 2013-05-01 15:05

> test

Name: Anonymous 2013-05-01 15:43

le shiggity niggity niggers

Name: Anonymous 2013-05-01 16:55

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

Name: Anonymous 2013-12-01 17:18

%░████▀▀▒▒▒▒▒░░░░▄▄▄▄▒▒▒▀▀███████░░
%░░██▒▒▄▄▒░░░░▒▒▀▒▒▒▒▒▒▒▒▒▒▒▒▀▀██▌░
%░░█▌▄▀▀▒▒▒▒▒▒▒▒▒▄▄▄▄▄▒▒▒▒▒▒▒▌▐▒█▐░
%░░▀▌▒▒▒▄▄▄▒▒▒▒▒▀▄▄█▀▒▒░▒▒▒▒▒▐▒▐▒█░
%░░░▐▒▄▀██▄▀▒▒▒▒▒▒▒░░░░▒▒▒▒▒▒▒▌▌▒█░
%░░░▐▒▒▒▒▒▒▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌▄▀█░
%░░░▐▒▒▒▒▒▒▌▒▒▒▒▀▄░░░▒▒▒▒▒▒▒▒▒▌▐██░
%░░░░▌▒▒▒▒▐▒▒▒▒▄▄▀░░░░▒▒▒▒▒▒▒▒▒▌▒█░
%░░░░▐▒▒▒▒▒▀▀▒▀▒▄▄▄▄░▒▒▒▒▒▒▒▒▒░███░
%░░░░░▌▒▒▒▄█▀▀▀▀▀▀▀▀█▒▒▒▒▒▒▒▒░▀▐██░
%░░░░░▐▒▒▒█▒▀████▀▀▒▐▌▒▒▒▒▒░▄▒▒▐░░░
%░░░░░░▐▒▒▀▒▒▒▒▒▒▒▒▒▒▐▒▒▒▒▄▒▒▒▄▐░░░
%░░░░░░▀▌▒▐▌▐▌▀▌▀▌▀▌▀▌▐▀▀▌▒▐▐▌▌▌▌░░
%░░░░░░░█▒▐▒▐▌▒▌▄▌▐▌▄▒▐▌▄▌▒█▌█▒▒▐░░
%░░░░░░░▐▌▌▒▐▌▒▌▒▒▐▌▒▄▐▌▀▄▒▒▒▒▒▒▒▀▄
%░░░░░░░░▀▒▐▀▀▒▀▒▒▀▀▀▀▒▀▒▀▀▒▒▒▒▒▒▒
%YOU'LL COWARDS DON'T EVEN SMOKE CRACK
%POST lN 3 THREADS OR YOU'LL COWARD

Name: Anonymous 2013-12-04 15:49

1. is the problem divisible into two or more parts? if not, goto 3
2. divide it, and for each part, execute step 3
3. would a lookup table be faster than actually running the code? if not, goto 6
4. make into lookup table
5. goto 1
6. your program is optimized

Name: Anonymous 2013-12-04 19:55

>>9
>le pedophile sage

Name: Anonymous 2013-12-06 2:13



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

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