17 lines
470 B
Clojure
17 lines
470 B
Clojure
(defn digits [n]
|
|
(->> n
|
|
(iterate #(quot % 10))
|
|
(take-while pos?)
|
|
(mapv #(mod % 10))
|
|
rseq))
|
|
(defn is-palindrome [n] (let [d (digits n)] (= d (reverse d))))
|
|
(defn pairs [s] (for [a s b s] [a b]))
|
|
(defn pow [b e] (reduce * 1 (repeat e b)))
|
|
(defn largest-palindrome [n]
|
|
(->> (range (pow 10 (dec n)) (pow 10 n))
|
|
(pairs)
|
|
(map (partial apply *))
|
|
(filter is-palindrome)
|
|
(apply max)))
|
|
|
|
(println (largest-palindrome 3))
|