Paste: naive fib

Author: glguy
Mode: factor
Date: Fri, 10 Apr 2009 17:56:47
Plain Text |
: fib ( x -- y )
  {
    { 0 [ 0 ] }
    { 1 [ 1 ] }
    [ [ 1 - fib ]
      [ 2 - fib ] bi + ]
  } case ;

( scratchpad ) 10 [ fib ] map .
{ 0 1 1 2 3 5 8 13 21 34 }

Annotation: without case

Author: glguy
Mode: factor
Date: Fri, 10 Apr 2009 17:58:01
Plain Text |
: fib ( x -- y )
  dup 1 <=
  [ [ 1 - fib ]
    [ 2 - fib ] bi +
  ] unless ;

New Annotation

Summary:
Author:
Mode:
Body: