Browse files

Problema 2 - Clojure

  • Loading branch information...
1 parent 2ac2627 commit 1891a6f022fb357c7a8ec365587de4114fe19908 @pbalduino committed Mar 7, 2014
Showing with 16 additions and 0 deletions.
  1. +16 −0 002/clojure/euler002_pbalduino.clj
View
16 002/clojure/euler002_pbalduino.clj
@@ -0,0 +1,16 @@
+(ns euler002-pbalduino)
+
+; Problem 2 - Even Fibonacci numbers
+
+; 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.
+
+; Source: https://projecteuler.net/problem=2
+
+(def fib-seq (lazy-cat [0 1] (map + (rest fib-seq) fib-seq)))
+
+(->> fib-seq
+ (take-while (partial > 4000000))
+ (filter even?)
+ (reduce +))

0 comments on commit 1891a6f

Please sign in to comment.