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

Forced Indentation of Fast Factorials

Name: Anonymous 2009-03-17 8:22

It took the python interpreter fucking 100 minutes to print all the indentation errors for my first attempt at this.
Insane indentation style is fucking insane.
I finally got it work, but it's ugly as hell and slow as slightly faster than usual fuck:
import math
from itertools import takewhile, dropwhile

def eratosthenes():
    D = {}
    q = 2
    while 1:
        if q not in D:
            yield q
            D[q*q] = [q]
        else:
            for p in D[q]:
                D.setdefault(p+q,[]).append(p)
            del D[q]
        q += 1

def bitcount(n):
    r = 0;
    while n > 0:
        r += n & 1
        n >>=1
    return r

def take(n, g):
    for i in range(n): yield g.next()

def swing(n):
    primes = list(takewhile(lambda x: x <= n, eratosthenes()))
    smalloddswing = [1,1,1,3,3,15,5,35,35,315,63,693,231,3003,429,6435,6435,109395,12155,230945,46189,969969,88179,2028117,676039,16900975,1300075,35102025,5014575,145422675,9694845,300540195,300540195]
    if n < 33: return smalloddswing[n]
    primelist = []
    rootn = long(math.sqrt(n))
    primesa = takewhile(lambda x: x <= rootn, dropwhile(lambda x: x < 3, primes))
    primesb = takewhile(lambda x: x <= n // 3, dropwhile(lambda x: x <= rootn, primes))
    for prime in primesa:
        q = n // prime
        p = 1
        while q > 0:
            if q & 1 == 1: p *= prime
            q //= prime
        if p > 1: primelist.append(p)
    return reduce(lambda x, y: x * y, list(takewhile(lambda x: x <= n, dropwhile(lambda x: x <= n // 2, primes))) + primelist + filter(lambda x: n // x & 1 == 1, primesb), 1)

def recfactorial(n):
    if n < 2: return 1
    return recfactorial(n // 2) ** 2 * swing(n)

def factorial(n):
    if n < 20: return reduce(lambda x, y: x * y, range(2,n + 1), 1)
    return recfactorial(n) << (n - bitcount(n))

Name: Anonymous 2009-03-17 8:30

How the hell can you indent python wrong? Unless you're retarded, that is.

Name: Anonymous 2009-03-17 8:52

>>2
All python is indented wrong.  The language requires it.

Name: Anonymous 2009-03-17 9:05

>>2
Obviously by trying to indent it like a sane language instead of putting things like
    smalloddswing = [1,1,1,3,3,15,5,35,35,315,63,693,231,3003,429,6435,6435,109395,12155,230945,46189,969969,88179,2028117,676039,16900975,1300075,35102025,5014575,145422675,9694845,300540195,300540195]
and
    return reduce(lambda x, y: x * y, list(takewhile(lambda x: x <= n, dropwhile(lambda x: x <= n // 2, primes))) + primelist + filter(lambda x: n // x & 1 == 1, primesb), 1)
all on one line.

Name: Anonymous 2009-03-17 9:10

Use a \

Name: Anonymous 2009-03-17 9:13

>>5
No thanks, it's ugly enough already.

Name: Anonymous 2009-03-17 9:28

>>1
Maybe you should go back to using the Troll language, Haskell.

Name: Anonymous 2009-03-17 10:06

>>4 You don't know Python, shithead.

>>> smalloddswing = [1,1,1,3,3,15,5,35,35,315,63,693,231,3003,429,
... 6435,6435,109395,12155,230945,46189,969969,88179,2028117,
... 676039,16900975,1300075,35102025,5014575,145422675,9694845,300540195,3005401
95
... ]
>>>
>>> def f():
...   return reduce(
...     lambda x, y: x * y
...     , list(
...        takewhile(
...          dropwhile(lambda x:
...             x <= n // 2, primes))) # oh I'm tired
... # it won't complain anyway!
...             , 1)
...
>>> print('FIOC' * 100)
FIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOC
FIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOC
FIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOC
FIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOC
FIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOCFIOC

>>>


No, seriously, isn't that absolutely ridiculous? You'd expect people to try just a little - if they are too lazy to read specs, maybe they could just, I don't know, experiment, or look at other people's code or anything. And not learn Python by reading other idiots' FIOC rants on /SICP/, for fuck's sake.

Name: Anonymous 2009-03-17 10:16

it's kinda funny how python requires you to import shit from modules with obscure names to get basic shit done.

Name: Anonymous 2009-03-17 15:37

from soul import soul
XD

Name: Trollbot9000 2009-07-01 10:18

Errors What do you lose abilities especially  INT as you  can uncomfortably sledgehammer  into your skull  ritalin does not  require variable declarations  It has explicit.

Name: Anonymous 2011-02-04 12:03

Name: Anonymous 2014-01-21 21:13

>>12
>le pedophile sage

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