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

Pages: 1-4041-

facts

Name: Anonymous 2009-04-21 8:46

ITT: Your favourite implementation of fact.

Mine would be:
fact x = foldr (*) 1 $ takeWhile (/= 1) [x,x-1..]
I wrote it today :3

Name: Anonymous 2009-04-21 9:32

THE FUCK ON

Name: Anonymous 2009-04-21 10:21

Did you mean foldr1 (*) [x, x-1 .. 1]

Read Gentle Introduction of Computer Programs.

Name: Anonymous 2009-04-21 10:33

Did you mean sub fact { [*] $^n..1:by(-1) }

Name: Anonymous 2009-04-21 10:47

print'FACT'

Name: Anonymous 2009-04-21 11:52

>>3
No I didn't.

Name: Anonymous 2009-04-21 12:13

>>6
Testing fact 10000.
>>1 is
2.74 secs, 22168752 bytes
>>3 is
2.16 secs, 22063012 bytes

>>4 is 13926.25 secs, 1702434189 bytes

Name: Anonymous 2009-04-21 12:46

What langwidge is >>4 anyway?, Perl?

Name: Anonymous 2009-04-21 12:55

>>7
How do you test them?
Also, I don't believe you actually tested >>4. Enjoy your accurate estimation.

Name: Anonymous 2009-04-21 13:17

>>1,3
slow factorials are slow.

primes = 2 : 3 : 5 : 7 : [k + r | k <- [0, 30..], r <- [11, 13, 17, 19, 23, 29, 31, 37], primeTest (k + r)]
    where primeTest n = all ((0 /=) . mod n) . takeWhile ((n >=) . join (*)) $ drop 3 primes

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

swing n | n < 33 = genericIndex smallOddSwing n
        | True   = 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 case x of
                                                         0 -> case p of
                                                                   1 -> []
                                                                   _ -> [p]
                                                         _ -> pListA x (p * prime ^ (mod x 2)) prime
          pListB = (filter ((1==) . flip mod 2 . div n) . takeWhile (<= div n 3) $ dropWhile ((<= n) . (^2)) primes)
          pListC = takeWhile (<= n) $ dropWhile (<= div n 2) primes
          pList = (concatMap (pListA n 1) . takeWhile ((n >=) . (^2)) $ tail primes) ++ pListB ++ pListC

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

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

Name: Anonymous 2009-04-21 13:20

>>9
:set +s
Read your GHCi User Manual.

Name: Anonymous 2009-04-21 13:35

>>11
>>4 is not Haskell, how did you test that?

Name: Anonymous 2009-04-21 13:42

Name: Anonymous 2009-04-21 13:51

>>13
faggot

Name: Anonymous 2009-04-21 13:53

Fun fact: op is sexually attracted to Haskell

Name: Anonymous 2009-04-21 13:59

need help with the hello world program?

Name: Anonymous 2009-04-21 14:02

>>15
He's probably too busy fapping to >>10 to read the rest of this thread.

Name: Anonymous 2009-04-21 14:11

>>12
He didn't test it, because I wrote it in THE HALFWAY IMPLEMENTED AFTER EIGHT GODDAMN YEARS LANGUAGE PERL6.

sub fact { [*] 1..$^n }, say fact 10000 will run, however, and it takes 5 seconds to about .5 for >>1,3And it prints Inf.

Name: Anonymous 2009-04-21 14:34

>>10
What
I don't understand.

Name: Anonymous 2009-04-21 14:37

if you're using floating point numbers or fixed-width integers, you can calculate factorials a lot faster.

but then you probably can't calculate 1000000!.

Name: Anonymous 2009-04-21 14:38

>>19
The algorithm PrimeSwing, ... the (asymptotical) fastest algorithm known to compute n!.

Name: Anonymous 2009-04-21 14:40

FV's lookup version is still faster.

Name: Anonymous 2009-04-21 14:44

>>22
Mine's even faster.
print "Number out of range"

Name: POINT-FREE MEME FAN 2009-04-21 14:46

fact = product.enumFromTo 1

Name: Anonymous 2009-04-21 14:47

>>23
But it doesn't work. FV's version works for reasonable input (i.e. in cases when it will be actually be used).

Name: Anonymous 2009-04-21 14:49

>>24
POINT-FREE
Did you mean pointless?

Name: Anonymous 2009-04-21 15:01

>>26
Actually, I did. I've been thinking about putting it in the name field all the time I've been writing my post, but then I forgot.  :( So, no, NHBT.

Name: HMA MEME FAN 2009-04-21 15:04

fact n = mapM_ putStrLn $ replicate n "HAX MY ANUS"

Name: Anonymous 2009-04-21 15:14

>>24
product . enumFromTo2 does the same thing.

>>25
1000000 is a reasonable input. it only takes about 20 seconds with >>10's code (and outputs a 5565709 digit number).

Name: REPLICATEM_ MEME FAN 2009-04-21 15:55

fact n = replicateM_ n $ putStrLn "HAX MY ANUS"

Name: Anonymous 2009-04-21 16:08

>>2
Back to /lounge/, please.

>>28,30
"HAX MY ANUS"

Thread was going so well too, dammit.

Name: Anonymous 2009-04-21 16:14

>>27
So now you're saying you wanted to be the ``POINTLESS MEME FAN''? I think you're lying. Which pointless meme are you a fan of?

Name: Anonymous 2009-04-21 16:28

>>30 MEMI REPLICATEM_ FAN EST

Name: Anonymous 2009-04-21 17:03

>>32
(Not >>27)
Does that even matter? ALL memes are pointless, they just produce more noise and irrelevance and kill discussion.

Name: Anonymous 2009-04-21 17:14

: fact ( n -- n! ) 1 + 1 tail-slice product ;

Name: Anonymous 2009-04-21 17:38

>>34
It's not your business. I'm questioning >>27.

Anyway, for an example of beneficial memes, see:
*The Sussman meme
*The SICP meme
*The HMA meme
*The recursive acronym meme

Name: Anonymous 2009-04-21 17:43

>>36
SICP and the Sussman are not memes.
They are the Way.

Name: Anonymous 2009-04-21 17:45

Beneficial?
The Sussman meme
No.
The SICP meme
It's a good book and people should read it.
The HMA meme
Absolutely not!
The recursive acronym meme
lol, RMS.

Name: Anonymous 2009-04-21 20:25

>>38
HMA my anus

Name: Anonymous 2009-04-22 0:15

>>39
Stop perpetuating this noise.

Name: Anonymous 2009-04-22 0:46

>>40
I can't help it, sorry.

Name: Anonymous 2009-04-22 3:50

Prelude> let fac 1=1
Prelude> let fac n = n * fac(n-1)
Prelude> fac 10
*** Exception: stack overflow

Name: Anonymous 2009-04-22 3:52

>>42
I never get tired of this meme.
I approve

Name: Anonymous 2009-04-22 3:55

>>43
I invented this meme

Name: Anonymous 2009-04-22 3:56

(I invented almost every meme except for shit ones like satori and hax my anus)

Name: Anonymous 2009-04-22 5:17

>>44
Thank you for your controbation.

Name: controbation 2009-04-22 11:45

>>46
Thank you im you're controbation

Name: Anonymous 2009-04-22 12:38

GHCi, version 6.10.2: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
*** Exception: stack overflow


lol ghci

Name: Anonymous 2009-04-22 13:16

GHCi, version 6.10.2
You trollan me, or is new version of ghc?

Name: Anonymous 2009-04-22 13:19

>>49

There is also a new version of English you should try.

Name: Anonymous 2009-04-22 13:21

>>50
good good

Name: Anonymous 2009-04-22 13:26

>>50
The current implementation of English is broken, the overall structure needs a rewrite.

Name: Anonymous 2009-04-22 13:29

hax my anus

Name: Anonymous 2009-04-22 13:47

>>52
Most people aren't going to upgrade if you don't keep the new version backwards compatible.

Name: Anonymous 2009-04-22 13:48

>>54
What did moot say to his gay lover in bed?

SNAX MY ANUS

Name: Anonymous 2009-04-22 14:08

>>55
I laughed. Then I cried.

Name: Anonymous 2009-04-22 14:12

>>49
Weeks ago.

Name: Anonymous 2009-08-17 0:08

Lain.

Name: Anonymous 2010-11-26 16:15

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