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

n! -- factor

Name: Anonymous 2007-09-14 9:02 ID:w+iUxD20


: n! ( n -- n! ) dup zero? [ drop 1 ] [ dup 1- n! * ] if ;
: ln! ( n lim -- ) over - [ dup n! . 1+ ] times drop ;

1 10 ln!
1
2
6
24
120
720
5040
40320
362880


Superior.

Name: Anonymous 2007-09-14 9:20 ID:j0wVmbUm

once in summer camp, i calculated the factorial of 1.000.000.000.000

the output was huge

Name: Anonymous 2007-09-14 9:23 ID:6Ro75jSG

>>1
Stackfag

Name: Anonymous 2007-09-14 9:39 ID:Heaven


: knuth ( x y -- z ) swap <array> 1 [ swap ^ ] reduce ;
: n$ ( n -- n$ ) n! dup knuth ;

http://en.wikipedia.org/wiki/Factorial#Superfactorials

Name: Anonymous 2007-09-14 9:59 ID:NGyWv0ND

"memoize" require
USING: memoize math.vectors ;
MEMO: memo-* ( a b -- c ) * ;
MEMO: n! ( n -- n! ) 1+ 1 tail 1 [ memo-* ] reduce ;
: ln! ( n lim -- ) swap tail [ n! . ] each ;


Superior.

Name: Anonymous 2007-09-14 10:11 ID:Heaven

>>5
( scratchpad ) : n! ( n -- n! ) dup zero? [ drop 1 ] [ dup 1- n! * ] if ;
( scratchpad ) : ln! ( n lim -- ) over - [ dup n! . 1+ ] times drop ;
( scratchpad ) \ n! compile
Compiling n!
( scratchpad ) [ 1 500 ln! ] time
...
3580 ms run / 59 ms GC time
( scratchpad ) "memoize" require
Loading P" resource:extra/memoize/memoize.factor"
Compiling 980 words...
Compile finished.

:errors - print 0 compiler errors.
:warnings - print 866 compiler warnings.

Loading P" resource:extra/memoize/memoize-docs.factor"
( scratchpad ) USING: memoize math.vectors ;
( scratchpad ) MEMO: memo-* ( a b -- c ) * ;
( scratchpad ) MEMO: n! ( n -- n! ) 1+ 1 tail 1 [ memo-* ] reduce ;
( scratchpad ) : ln! ( n lim -- ) swap tail [ n! . ] each ;
( scratchpad ) \ n! compile
Compiling n!
Compiling memo-*
( scratchpad ) [ 1 500 ln! ] time
3308 ms run / 55 ms GC time

lol whut

Name: Anonymous 2007-09-14 11:16 ID:6YKGRXRM

Superior.
[def] mult
    [ls]a b[/ls]
    [if] [equal][var]a[/var] 1[/equal]
        [var]b[/var]
        [add][var]b[/var] [mult][sub][var]a[/var] 1[/sub] [var]b[/var][/mult][/add]
    [/if]
[/def]

[def] fact
    [ls]n[/ls]
    [if] [equal][var]n[/var] 0[/equal]
        1
        [mult][var]n[/var] [fact][sub][var]n[/var] 1[/sub][/fact][/mult]
    [/if]
[/def]

[fact]6[/fact]

Name: Anonymous 2007-09-14 11:24 ID:w+iUxD20

>>6
If you care about speed execution do not calculate the factorial each time.

example

n lim --
var = n!(n)
while(n++ < lim)
  output(var)
  var = *(var n)


Something like that.

Name: Anonymous 2007-09-14 12:14 ID:6Ro75jSG

>>7
Scheme BBCode is superior
[define [fact n]
    [define [fact-iter a n]
        [if [= n 1]
            a
            [fact-iter [* a n] [- n 1]]]]
    [fact-iter 1 n]]

Name: Anonymous 2007-09-14 12:19 ID:mnwZuDu3

>>2
So that's why the universe suddenly got so cramped. I'm glad you didn't finish.

Name: Anonymous 2007-09-14 13:05 ID:j0wVmbUm

>>10
I did finish it, took an hour or something. Was for Project Euler.

Name: Anonymous 2007-09-14 13:28 ID:DdRq6Qy2

Forth is what people used to avoid 3-register 6502 assembly in 1977. Shittiest shit since shit came to shit-town.

Name: 1977 2007-09-14 14:24 ID:P3zM9hKK

>>12
HEY YOU FUCK, YOU FORGOT ABOUT THE 4TH REGISTER, THE STACK POINTER (.S)

Name: Anonymous 2007-09-14 14:24 ID:gExlcikP

>>9
BUT THAT'S JUST SCHEME WITH SQUARE BRACKETS

Name: Anonymous 2007-09-14 15:16 ID:mnwZuDu3

>>11
Assuming you meant 1000000000000!, no you didn't. It'd have like 1000000000000^1000000000000 digits in it. (Well, close enough to not matter.)

If you meant 1!, well okay, but then you're just slow and that must've been one fucking huge 1.

Name: Anonymous 2007-09-14 16:17 ID:IOAqu+JE

>>15
Yes I did. Calculated fac(1000000000000) and wrote it to a file. My computer crashed several times trying to load the file. OpenOffice could open it. Got the right answer for the problem.

Fun fact: I printed it to the eclipse console first. Don't do that.

Name: Anonymous 2007-09-14 16:23 ID:DdRq6Qy2

>>13
Woo hoo, a whole page (256 bytes) of stack! RAISE THE FUCKING ROOF.

Name: Anonymous 2007-09-14 17:40 ID:IC/ZrGCM

>>11

no wonder you fail, each question supposed to only last a minute

Name: Anonymous 2007-09-16 7:10 ID:M62Rq+Kz

>>16

post the file or it didn't happen

Name: Anonymous 2007-09-16 8:01 ID:rwHGZUau

>>16
How big was it, file-wise?

Name: Anonymous 2009-07-12 7:01

  wait signal license, license, and me! What of 133745639 133745639   maybe you into I is to Flash for

Name: Anonymous 2010-11-15 3:01


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