Created
January 24, 2012 22:56
-
-
Save biesnecker/1673274 to your computer and use it in GitHub Desktop.
Project Euler solutions in Clojure (4-6)
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
(defn palindrome? [n] (let [numseq (seq (str n))] (= (reverse numseq) numseq))) | |
(defn euler-4 [] | |
(apply max | |
(for [x (range 999 900 -1) y (range x 900 -1) | |
:when (palindrome? (* x y))] | |
(* x y)))) |
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
(defn divisible-by-sequence? [n xs] | |
(every? zero? (map #(rem n %) xs))) | |
(defn euler-5 [] | |
(first (filter #(divisible-by-sequence? % (range 11 21)) (iterate #(+ 2520 %) 2520)))) |
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
(defn euler-6 [] | |
(let [nums (range 1 101) | |
s1 (int (Math/pow (reduce + nums), 2)) | |
s2 (int (reduce + (map #(Math/pow % 2) nums)))] | |
(- s1 s2))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment