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

Double factorial

Name: Anonymous 2009-02-27 13:02

GHCi, version 6.8.2: http://www.haskell.org/ghc/  :ihbt for help
Loading package base ... linking ... done.
Prelude> let fact n = product [1..n]
Prelude> fact 5
120
Prelude> let doubleFact = fact.fact
Prelude> doubleFact 3
720
Prelude>

Name: Anonymous 2009-02-27 13:09



    HULLO,

     IM 13 YEERS OLD AND I NO HASKELL, I AM SOOOO SMART

Name: Anonymous 2009-02-27 13:15

>>1
I came buckets

Name: Anonymous 2009-02-27 14:16

GHCi, version 6.8.2: http://www.haskell.org/ghc/  :ihbt for help
Loading package base ... linking ... done.
Prelude> let nigg n = watermelon [1..n]
Prelude> nigg 5
"muhfugen bix nood"
Prelude> let doubleNigg = nigg.nigg
Prelude> doubleNigg 3
"mup da doo didda po mo gub bidda be dat tum muhfugen bix nood cof bin dub ho muhfugga"
Prelude>

Name: Anonymous 2009-02-27 15:16

>>1
import List
import Control.Arrow

primes = 2 : 3 : [k + r | k <- [6, 12..] , r <- [-1, 1], all ((0 /=) . mod (k + r)) $ takeWhile ((<= k + r) . (^ 2)) primes]

factorize n = factorize' n [] $ takeWhile (<= n) primes
    where factorize' n fs []     = n:fs
          factorize' n fs (p:ps) = let (q, r) = divMod n p in if r == 0 then factorize' q (p:fs) (p:ps) else factorize' n fs ps

bitCount 0 = 0
bitCount n = uncurry (+) . (bitCount *** id) $ divMod n 2

primorial l h = product . takeWhile (<= h) $ dropWhile (< l) primes

swing n | n < 33 = genericIndex smallOddSwing n
        | True   = primorial (div n 2 + 1) n * product pList
    where 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]
          pListA q p prime = let x = div q prime in if x > 0 then if mod x 2 == 1 then pListA x (p * prime) prime else pListA x p prime else if p > 1 then [p] else []
          pListB prime = if mod (div n prime) 2 == 1 then [prime] else []
          pList = (concatMap (pListA n 1) . takeWhile ((<= n) . (^ 2)) $ tail primes) ++ (concatMap pListB . takeWhile (<= div n 3) $ dropWhile ((<= n) . (^ 2) . (-1 +)) primes)

rFact n | n < 2 = 1
        | True  = rFact (div n 2) ^ 2 * swing n

fact n | n < 20 = product [2..n]
       | True   = rFact n * 2 ^ (n - bitCount n)

Name: Anonymous 2009-02-27 15:31

>>5
Dude.

Name: FrozenVoid 2009-02-27 15:38

Factorizing integers to compute factorials seems wasteful to me.

Name: Anonymous 2009-02-27 15:50

>>6,7
http://www.luschny.de/math/factorial/FastFactorialFunctions.htm
The algorithm PrimeSwing, because it is the (asymptotical) fastest algorithm known to compute n!. The algorithm is based on the notion of the 'Swing Numbers' and computes n! via the prime factorization of these numbers.

Name: Anonymous 2009-02-27 15:55

And here is an algorithm which nobody needs, for the Simple-Minded only:
long factorial(long n) { return n <= 1 ? 1 : n * factorial(n-1); }
Do not use it if n > 12.

lolwhat.

Name: FrozenVoid 2009-02-27 16:16

>>8
So its faster to factorize 10,9,8,7,6,5,4,2,1 and then multiply their factors then to just multiply 10*9*8*7*6*5*4*2*1?

Name: Haxus the Lesser 2009-02-27 16:36

Haxus the Lesser

Name: Haxus the Great 2009-02-27 16:38

Haxus the Great

Name: Haxus the Lesser 2009-02-27 16:48

Haxus the Lesser

Name: Haxus the Great 2009-02-27 16:58

Haxus the Great

Name: Haxus the Spaceship Operator 2009-02-27 17:32

Haxus the Spaceship Operator

Name: Haxus the Dog 2009-02-27 17:43

Haxus the Dog

Name: Haxus the Sussman 2009-02-27 17:46

Haxus the Sussman

Name: Anonymous 2009-02-27 18:08

Please stop that.

Name: Haxus !HAXUS.HBkU 2009-02-27 18:42

Are you denying the greatness of me?

Name: Anonymous 2009-02-27 18:44

>>19
yes.

Name: Anonymous 2009-02-27 18:59

Hax the Gibson

Name: Anonymous 2009-02-27 19:01

>>19
I invented you.

Name: Haxus !HAXUS.HBkU 2009-02-27 19:05

>>22
Then uninvent me, post-haste.

Name: Anonymous 2009-02-27 19:21

unsafePerformUninventMeme

Name: Anonymous 2009-02-27 19:27

>>24
Not a meme.

Name: Haxus meme fan 2009-02-27 19:34

>>24
How dare you

Name: Anonymous 2009-02-27 20:00

>>26
Terrible!

Name: asdf 2009-02-27 20:12

1 866 834 2488 free phone sex monday - through friday 1:00 - 9:00 
call us alredy masterbating!!
1 866 834 2488

Name: Anonymous 2009-02-27 20:24

>>28
You can't even spell mastorbating correctly.

Name: Anonymous 2009-02-27 20:28

>>28
why not saturdays

Name: Anonymous 2010-11-26 9:00

Name: Anonymous 2010-12-06 9:07

Back to /b/, ``GNAA Faggot''

Name: Anonymous 2010-12-26 10:03

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