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

One Line Factorial

Name: Anonymous 2009-06-15 15:56

for(int a1=1,a2=1,i=scanf_s("%d",&i)+i-1;(i--)>2; a1=(a2+=a1)-a1,(i==2)?printf_s("Result=%d\n",a2):NULL)

Name: Anonymous 2009-06-19 15:15

Scheme: (time (factorial 1000))
cpu time: 0 real time: 47 gc time: 0

Name: Anonymous 2009-06-19 15:18

>>39-41
try factorial(100000) for a real test.

Name: tehmeh 2009-06-19 15:22

obviously my system

Name: just another schemer 2009-06-19 15:30

(time (factorial 100000))
cpu time: 121672 real time: 121716 gc time: 25207

Name: tehmeh 2009-06-19 15:33

factorial(100000)
Time taken: 166.082072973s

Name: just another schemer 2009-06-19 15:34

>>44
should note these units are milliseconds.

Name: Anonymous 2009-06-19 15:46

my computer broke

Name: Anonymous 2009-06-19 15:58

>>46,45
using >>7's haskell code: (6.35 secs, 319380256 bytes)

much faster than your slow shit.

Name: just another schemer 2009-06-19 16:42

>>48
And more functional, amirite?????? LOLOLOL

Name: Anonymous 2009-06-19 17:30

The thread is about a One Line Factorial implementation, not about fast factorial implementations. Enjoy your small penises.

Name: Anonymous 2009-06-19 17:34

>>48
Using >>7's haskell:

7.hs:12:1: parse error (possibly incorrect indentation)

After fixing that:
7.hs:2:67: Not in scope: `join'
7.hs:5:23: Not in scope: `shiftR'
7.hs:5:39: Not in scope: `.&.'
7.hs:7:19: Not in scope: `genericIndex'
7.hs:17:41: Not in scope: `.&.'
7.hs:17:105: Not in scope: `join'
7.hs:18:52: Not in scope: `shiftR'
7.hs:19:64: Not in scope: `join'
7.hs:22:25: Not in scope: `join'
7.hs:26:23: Not in scope: `shiftL'


After importing Control.Monad, Data.List and Data.Bits:
7.hs:26:25:
    No instance for (Monad ((->) Integer))
      arising from a use of `join' at 7.hs:26:25-57
    Possible fix:
      add an instance declaration for (Monad ((->) Integer))
    In the first argument of `(*)', namely
        `join (*) (recFactorial $ div n 2)'
    In the expression: join (*) (recFactorial $ div n 2) * swing n
    In the definition of `recFactorial':
        recFactorial n | n < 2 = 1
                       | True = join (*) (recFactorial $ div n 2) * swing n

Name: tehmeh 2009-06-19 18:13

>>50
def fact(x): return (1 if x==0 else x * fact(x-1))

ORIGINAL CODE DO NOT STEAL

Name: Anonymous 2009-06-19 19:02

Name: Anonymous 2009-06-19 19:33

Reasonably fast and reasonably one line:
(lambda (n) (let l ((a 1) (n n)) (if (< n 2) a (let ((h (quotient n 2))) (* (l (+ a h) (- n h)) (l a h))))))

Name: Anonymous 2009-06-19 21:35

int fac(int a){
a ? a * fac(a - 1) : 1;
}

Name: Anonymous 2009-06-20 0:44

>>51
Control.Monad.Instances

>>50
My penis doesn't fit on one line.

Name: Anonymous 2009-06-20 5:08

u guys suck at this, heres mine

the game

Name: Anonymous 2009-06-20 7:49

>>57
Please halt.

Name: Anonymous 2009-06-20 11:03

>>56
I bet it does if you set your font size to 12pt, dickie.

Name: Anonymous 2009-06-20 17:23

>>59
I don't think changing my font size from 10pt to 12pt would do that.

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