Paste: Naive Fibonacci function

Author: pozorvlak
Mode: factor
Date: Thu, 7 May 2009 11:11:31
Plain Text |
: fib ( n -- f ) dup 1 <=
    [ drop 1 ]
    [ [ 1 - fib ] [ 2 - fib ] bi + ] if ;

Annotation: Better version

Author: prunedtree
Mode: factor
Date: Thu, 7 May 2009 11:32:54
Plain Text |
: fib ( n -- n' ) dup 2 > [ { 1 2 } [ - fib ] with map sum ] when ;

Annotation: Shorter better version

Author: prunedtree
Mode: factor
Date: Thu, 7 May 2009 11:35:31
Plain Text |
: fib ( n -- n' ) 1 1 rot [ tuck + ] times drop ;

Annotation: boring version

Author: pruned
Mode: factor
Date: Thu, 7 May 2009 12:14:26
Plain Text |
: fib ( n -- n' ) { { 1 1 } { 1 0 } } swap m^n first second ;

: m^n ( m n -- n ) make-bits over first length identity-matrix [ [ dupd m. ] when [ dup m. ] dip ] reduce nip ;

Annotation: MEMO version

Author: elasticdog
Mode: factor
Date: Thu, 7 May 2009 14:55:53
Plain Text |
MEMO: fib ( m -- n )
    dup 1 > [ [ 1 - fib ] [ 2 - fib ] bi + ] when ;

New Annotation

Summary:
Author:
Mode:
Body: