Paste: fibonacci

Author: hotaru
Mode: factor
Date: Tue, 12 Oct 2010 08:51:35
Plain Text |
: twoFibs ( n -- b a ) [ zero? not ]
                     [ 2 /mod [ twoFibs [ dupd 2 * + * ] [ [ sq ] bi@ + ] 2bi ] dip
                       { { 0 [ ] }
                         { 1 [ swap [ + ] keep ] } } case ]
                     [ 0 1 ] smart-if* ;

: fib ( n -- f ) twoFibs drop ;

: fib-matrix ( n -- f ) { { 0 1 } { 1 1 } } swap m^n second first ;

! ( scratchpad ) [ 22390 fib-matrix drop ] time
! Running time: 0.038835103 seconds
! 
! Additional information was collected.
! dispatch-stats.  - Print method dispatch statistics
! gc-events.       - Print all garbage collection events
! gc-stats.        - Print breakdown of different garbage collection events
! gc-summary.      - Print aggregate garbage collection statistics
! ( scratchpad ) [ 22390 fib drop ] time
! Running time: 0.007272432 seconds
! 
! Additional information was collected.
! dispatch-stats.  - Print method dispatch statistics
! gc-events.       - Print all garbage collection events
! gc-stats.        - Print breakdown of different garbage collection events
! gc-summary.      - Print aggregate garbage collection statistics

New Annotation

Summary:
Author:
Mode:
Body: