Created
September 12, 2009 09:23
-
-
Save Wilfred/185773 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; code for project euler problem 1 | |
| (defn returnIfFactor | |
| [x] | |
| (if (or (= (mod x 5) 0) (= (mod x 3) 0)) | |
| x | |
| 0)) | |
| (defn problem1 | |
| [x] | |
| (if (= x 0) | |
| 0 | |
| (+ (returnIfFactor x) (problem1 (- x 1))))) | |
| (println (problem1 999)) | |
| ; euler problem 2 | |
| (defn fibs [x y] | |
| (lazy-seq | |
| (cons x (fibs y (+ x y))))) | |
| (defn problem2 [l] | |
| (if (>= (first l) 4000000) | |
| 0 | |
| (if (even? (first l)) | |
| (+ (first l) (problem2 (rest l))) | |
| (problem2 (rest l))))) | |
| (println (problem2 (fibs 1 2))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment