Created
June 21, 2011 04:12
-
-
Save sjl/1037222 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
(defn palindrome? [coll] | |
(= coll | |
(reverse coll))) | |
(defn n-digit-ints [n] | |
(range (expt 10 (- n 1)) | |
(expt 10 n))) | |
(defn p4 [n] | |
(let [choices (for [a (reverse (n-digit-ints n)), | |
b (reverse (n-digit-ints n))] | |
(* a b))] | |
(apply max (->> choices ; choices -> seq of ints | |
(map str) ; -> convert to strings | |
(map #(apply vector %)) ; -> convert to vectors | |
(filter palindrome?) ; select just the palindromes | |
(map #(apply str %)) ; -> back to strings | |
(map #(Integer. %)))))) ; -> back to ints |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some time ago I came across this: http://www.rs.io/euler-4-in-clojure/ :-)