Paste: euler-2

Author: ditto
Mode: factor
Date: Sat, 14 Feb 2009 08:29:18
Plain Text |
! Copyright (C) 2009 Kim Taeho.
! See http://factorcode.org/license.txt for BSD license.
USING: locals sequences kernel math ;
IN: euler-2

: next-fib-term ( seq -- n ) 2 tail* sum ;

: next-fib-seq ( seq -- newseq ) dup next-fib-term suffix ;

: exceeds-limit? ( seq -- ? ) peek 4000000 > ;

:: fib-seq ( seq -- newseq )
  seq next-fib-term exceeds-limit? [ seq ] [ seq next-fib-seq fib-seq ] if ;

: solve ( -- n ) { 1 2 } fib-seq [ even? ] filter sum ;

New Annotation

Summary:
Author:
Mode:
Body: