Guest User

Untitled

a guest
May 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. ; 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:
  2.  
  3. ; 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
  4.  
  5. ; Find the sum of all the even-valued terms in the sequence which do not exceed four million.
  6.  
  7. (defun calc-next (a b) (+ a b))
  8.  
  9. (defun multiple-of (x y) (= 0 (rem x y)))
  10.  
  11. (let ((answer 2) (a 1) (b 2) n)
  12. (loop while (< b 4000000) do
  13. (setf n (calc-next a b))
  14. (when (multiple-of n 2) (setf answer (+ answer n)))
  15. (setf a b)
  16. (setf b n))
  17. (print answer))
Add Comment
Please, Sign In to add comment