Skip to content

Instantly share code, notes, and snippets.

@jordangarcia
Created February 12, 2013 06:00
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/4760553 to your computer and use it in GitHub Desktop.
Save jordangarcia/4760553 to your computer and use it in GitHub Desktop.
(ns test1.prob4)
(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 prob4 [start]
(loop [x start, y start]
(println (str x " " y))
(def results [])
(if (palindromic-number? (* x y))
(conj results (* x y)))
(if (and (= x 1) (= y 1))
results
(if (= x 1)
(recur start (dec y))
(recur (dec x) y)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment