Skip to content

Instantly share code, notes, and snippets.

@wildermuthn
Created January 15, 2014 18:55
Show Gist options
  • Save wildermuthn/8442096 to your computer and use it in GitHub Desktop.
Save wildermuthn/8442096 to your computer and use it in GitHub Desktop.
; ProjectEuler.net
;; Even Fibonacci numbers
;; Problem 2
;; 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, ...
;;
;; By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
(defun fsequence (limit)
(do ((x 1 y)
(y 2 (+ x y))
(even-sum 0 (if (evenp y) (+ even-sum y) even-sum))
(sum 1 (+ sum y))
(f-list (list 1) (push y f-list)))
((>= y (1- limit)) even-sum)))
(defun answer ()
(fsequence 4000000)) ; 4613732
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment