one-file-projects/palindrome.clj
Valentin Gehrke b8b6518057 3 more files
Signed-off-by: Valentin Gehrke <madmaurice@zom.bi>
2016-11-09 02:02:03 +01:00

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))