Guest User

Untitled

a guest
Jul 16th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. ; Project Euler Problem 2
  2. ; Solution by nathan dotz - nathan (period) dotz (at sign) gmail (period) com
  3. ;
  4. ; Each new term in the Fibonacci sequence is generated by adding
  5. ; the previous two terms. By starting with 1 and 2, the first
  6. ; 10 terms will be:
  7. ; 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
  8. ;
  9. ; Find the sum of all the even-valued terms in the sequence
  10. ; which do not exceed four million.
  11. ;
  12.  
  13. (defun fib (n)
  14. (defun fib-worker (n stack)
  15. (if (<= n (car stack))
  16. (cdr stack)
  17. (fib-worker n (cons (+ (first stack) (second stack)) stack))))
  18. (fib-worker n '(1 1))
  19. )
  20.  
  21. (defun even-small-fib (small-fib)
  22. (remove-if-not 'evenp small-fib)
  23. )
  24.  
  25. (princ (apply '+ (even-small-fib (fib 4000000)) ) )
Add Comment
Please, Sign In to add comment