Most of my time was spent playing with for, trying to work out if it was best to do it all in the list comprehension. In the end I thought it was more readable to pull the creation of the products out into its own function.
(defn palindrome? [str]
(if (= (first str) (last str))
(if (<= 2 (count str))
(recur (rest (butlast str)))
true)
false))
(defn three-digit-numbers []
(range 100 1000))
(defn- products []
(distinct
(for [n1 (three-digit-numbers) n2 (three-digit-numbers)]
(* n1 n2))))
(defn solve []
(apply max (filter #(palindrome? (str %)) (products))))
Org-mode PDF export failure
-
Having replaced my laptop due to a tea related accident, I am finding a few
things that I need to reconfigure. Org exports are one of them. On my new
fedor...
14 years ago
No comments:
Post a Comment