Created
April 6, 2015 13:25
-
-
Save jmorton/e230de3d3bf099932c90 to your computer and use it in GitHub Desktop.
This file contains 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
(ns shokunin.euler) | |
;; sum of multiples of 3 and 5 < 1000 | |
;; https://projecteuler.net/problem=1 | |
(defn multiple-seq [n] | |
(iterate (partial + n) n)) | |
(let [x3 (take-while #(< % 1000) (multiple-seq 3)) | |
x5 (take-while #(< % 1000) (multiple-seq 5)) | |
xs (clojure.set/union (set x3) (set x5))] | |
(apply + xs)) | |
;; sum of even fibonacci numbers below 4 million | |
;; https://projecteuler.net/problem=2 | |
(defn fib-seq | |
([] (fib-seq 1 1)) | |
([x y] (cons x (lazy-seq (fib-seq y (+ x y)))))) | |
(reduce + (filter even? (take-while (fn [x] (< x 4000000)) (fib-seq)))) | |
;; largest prime factor | |
;; https://projecteuler.net/problem=3 | |
(defn prime? [n] true) ; tbd | |
(defn factors [n] [1 2 3 4]) ; tbd | |
(apply max (filter prime? (factors 42))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment