Skip to content

Instantly share code, notes, and snippets.

@sjl
Created June 21, 2011 04:12
Show Gist options
  • Save sjl/1037222 to your computer and use it in GitHub Desktop.
Save sjl/1037222 to your computer and use it in GitHub Desktop.
(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
@caleywoods
Copy link

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.

@mnicky
Copy link

mnicky commented Jun 21, 2011

Some time ago I came across this: http://www.rs.io/euler-4-in-clojure/ :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment