Skip to content

Instantly share code, notes, and snippets.

@jordangarcia
Created February 12, 2013 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordangarcia/4773571 to your computer and use it in GitHub Desktop.
Save jordangarcia/4773571 to your computer and use it in GitHub Desktop.
(ns euler.p4)
(defn palindromic-number? [x]
(let [arr (vec (.toString x)), size (count arr)]
(loop [x 0]
(if (not= (get arr x) (get arr (- size x 1)))
false
(if (> x (/ size 2))
true
(recur (inc x)))))))
(defn solve [start]
(loop [col 0]
(def coltry
(for [
x (reverse (if (= col 0)
(range 1)
(range col (- col
(int (Math/ceil (/ col 2)))
(if (even? col) 1 0))
-1)
))
:let [y (- col x), n1 (- start x), n2 (- start y), p (* n1 n2), found false]
:when (palindromic-number? p)
]
[p n1 n2])
)
(if (not-empty coltry)
(println (first coltry))
(when (< col start)
(recur (inc col))))))
(time (solve 999))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment