Paste: p2

Author: thomcc
Mode: factor
Date: Sat, 5 May 2012 20:59:28
Plain Text |
! problem 2: sum of even valued fib numbers less than 4 million

:: fibs ( max -- seq )
    { 0 1 }
    [ dup second max < ]
    [| p | p second dup p first + 2array dup ]
    produce
    nip
    [ first ] map ;

: problem2 ( max -- soln ) fibs [ even? ] filter sum ;

! 4000000 problem2 .
! => 4613732

New Annotation

Summary:
Author:
Mode:
Body: