Skip to content

Instantly share code, notes, and snippets.

@jmorton
Created April 6, 2015 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmorton/e230de3d3bf099932c90 to your computer and use it in GitHub Desktop.
Save jmorton/e230de3d3bf099932c90 to your computer and use it in GitHub Desktop.
(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