Created
February 12, 2013 21:31
-
-
Save jordangarcia/4773571 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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