12345678910111213141516171819202122232425262728293031323334 |
- ;; 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.
- (defvar x 1)
- (defvar y 2)
- ;; we are setting the sum equal to the sum of the first 3 fibonacci numbers: 1, 1, 2
- (defvar sum 4) ;; sum = 1 + 1 + 2
- (defun next-fib-number ()
- "finds the next fibonacci number"
- (cond
- ((< x y)
- (setq x (+ x y)))
- ((< y x)
- (setq y (+ x y)))))
- (next-fib-number)
- (defvar i 0)
- (while (< i 4000000)
- (setq sum (+ sum (next-fib-number)))
- (setq i (+ i 1)))
- (print sum)
- (provide '2)
- ;;; 2.el ends here
|