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
I just read that one last week. Haven't started yet on a solution. #2 was a little interesting but I got #3 solved in about 5 minutes without using the already existing factorization function from the Prime class.
Clojure looks interesting, i've not spent enough time with it though to understand much about it.