facts
1
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
2
Name:
Anonymous
2009-04-21 9:32
THE FUCK ON
3
Name:
Anonymous
2009-04-21 10:21
Did you mean foldr1 (*) [x, x-1 .. 1]
Read Gentle Introduction of Computer Programs.
4
Name:
Anonymous
2009-04-21 10:33
Did you mean sub fact { [*] $^n..1:by(-1) }
5
Name:
Anonymous
2009-04-21 10:47
print'FACT'
6
Name:
Anonymous
2009-04-21 11:52
7
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
8
Name:
Anonymous
2009-04-21 12:46
What langwidge is
>>4 anyway?, Perl?
9
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.
10
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)
11
Name:
Anonymous
2009-04-21 13:20
>>9
:set +s
Read your
GHCi User Manual .
12
Name:
Anonymous
2009-04-21 13:35
>>11
>>4 is not Haskell, how did you test that?
13
Name:
Anonymous
2009-04-21 13:42
14
Name:
Anonymous
2009-04-21 13:51
15
Name:
Anonymous
2009-04-21 13:53
Fun fact: op is sexually attracted to Haskell
16
Name:
Anonymous
2009-04-21 13:59
need help with the hello world program?
17
Name:
Anonymous
2009-04-21 14:02
>>15
He's probably too busy fapping to
>>10 to read the rest of this thread.
18
Name:
Anonymous
2009-04-21 14:11
>>12
He didn't test it, because I wrote it in
THE HALFWAY IMPLEMENTED AFTER EIGHT GODD AMN YEARS LANGUAGE PERL6 .
sub fact { [*] 1..$^n }, say fact 10000 will run, however, and it takes 5 seconds to about .5 for
>>1,3 .
And it prints Inf .
19
Name:
Anonymous
2009-04-21 14:34
>>10
What
‽
I don't understand
.
20
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!.
21
Name:
Anonymous
2009-04-21 14:38
>>19
The algorithm PrimeSwing , ... the (asymptotical) fastest algorithm known to compute n!.
22
Name:
Anonymous
2009-04-21 14:40
FV's lookup version is still faster.
23
Name:
Anonymous
2009-04-21 14:44
>>22
Mine's even faster.
print "Number out of range"
24
Name:
POINT-FREE MEME FAN
2009-04-21 14:46
fact = product.enumFromTo 1
25
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).
26
Name:
Anonymous
2009-04-21 14:49
>>24
POINT-FREE
Did you mean
pointless ?
27
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.
28
Name:
HMA MEME FAN
2009-04-21 15:04
fact n = mapM_ putStrLn $ replicate n "HAX MY ANUS"
29
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).
30
Name:
REPLICATEM_ MEME FAN
2009-04-21 15:55
fact n = replicateM_ n $ putStrLn "HAX MY ANUS"
31
Name:
Anonymous
2009-04-21 16:08
>>2
Back to /lounge/, please.
>>28,30
"HAX MY ANUS"
Thread was going so well too, dammit.
32
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?
33
Name:
Anonymous
2009-04-21 16:28
>>30 MEMI REPLICATEM_ FAN EST
34
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.
35
Name:
Anonymous
2009-04-21 17:14
: fact ( n -- n! ) 1 + 1 tail-slice product ;
36
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
37
Name:
Anonymous
2009-04-21 17:43
>>36
SICP and the Sussman
are not memes .
They are
the Way .
38
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.
39
Name:
Anonymous
2009-04-21 20:25
40
Name:
Anonymous
2009-04-22 0:15
>>39
Stop perpetuating this noise.
41
Name:
Anonymous
2009-04-22 0:46
>>40
I can't help it, sorry.
42
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
43
Name:
Anonymous
2009-04-22 3:52
>>42
I never get tired of this meme.
I approve
44
Name:
Anonymous
2009-04-22 3:55
>>43
I invented this meme
45
Name:
Anonymous
2009-04-22 3:56
(I invented almost every meme except for shit ones like satori and hax my anus)
46
Name:
Anonymous
2009-04-22 5:17
>>44
Thank you for your controbation.
47
Name:
controbation
2009-04-22 11:45
>>46
Thank you im you're controbation
48
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
49
Name:
Anonymous
2009-04-22 13:16
GHCi, version 6.10.2
You trollan me, or is new version of ghc?
50
Name:
Anonymous
2009-04-22 13:19
>>49
There is also a new version of English you should try.
51
Name:
Anonymous
2009-04-22 13:21
52
Name:
Anonymous
2009-04-22 13:26
>>50
The current implementation of English is broken, the overall structure needs a rewrite.
53
Name:
Anonymous
2009-04-22 13:29
hax my anus
54
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.
55
Name:
Anonymous
2009-04-22 13:48
>>54
What did moot say to his gay lover in bed?
SNAX MY ANUS
56
Name:
Anonymous
2009-04-22 14:08
>>55
I laughed.
Then I cried .
57
Name:
Anonymous
2009-04-22 14:12
58
Name:
Anonymous
2009-08-17 0:08
Lain.
59
Name:
Anonymous
2010-11-26 16:15