```factor
! Copyright (c) 2007 Aaron Schaefer.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel math sequences ;
IN: project-euler.002

! http://projecteuler.net/index.php?section=problems&id=2

! DESCRIPTION
! -----------

! Each new term in the Fibonacci sequence is generated by adding the previous
! two terms. By starting with 1 and 2, the first 10 terms will be:

!     1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

! Find the sum of all the even-valued terms in the sequence which do not exceed one million.


! SOLUTION
! --------

<PRIVATE

: (fib-upto) ( seq n limit -- seq )
    2dup <= [ >r add dup 2 tail* sum r> (fib-upto) ] [ 2drop ] if ;

PRIVATE>

: fib-upto ( n -- seq )
    { 0 } 1 rot (fib-upto) ;

: euler002 ( -- answer )
    1000000 fib-upto [ even? ] subset sum ;

! [ euler002 ] 100 ave-time
! 0 ms run / 0 ms GC ave time - 100 trials

MAIN: euler002
```

Use vectors instead of arrays in solution to Project Euler problem 2
user
```factor
! Copyright (c) 2007 Aaron Schaefer.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel math sequences ;
IN: project-euler.002

! http://projecteuler.net/index.php?section=problems&id=2

! DESCRIPTION
! -----------

! Each new term in the Fibonacci sequence is generated by adding the previous
! two terms. By starting with 1 and 2, the first 10 terms will be:

!     1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

! Find the sum of all the even-valued terms in the sequence which do not exceed one million.


! SOLUTION
! --------

<PRIVATE

: (fib-upto) ( seq n limit -- seq )
    2dup <= [ [ over push dup 2 tail* sum ] dip (fib-upto) ] [ 2drop ] if ;

PRIVATE>

: fib-upto ( n -- seq )
    V{ 0 } clone 1 rot (fib-upto) ;

: euler002 ( -- answer )
    1000000 fib-upto [ even? ] subset sum ;

! [ euler002 ] 100 ave-time
! 0 ms run / 0 ms GC ave time - 100 trials

MAIN: euler002
```
assistant