Skip to content

Instantly share code, notes, and snippets.

@thattommyhall
Created December 17, 2012 14:13
Show Gist options
  • Save thattommyhall/4318565 to your computer and use it in GitHub Desktop.
Save thattommyhall/4318565 to your computer and use it in GitHub Desktop.
(def __
(fn [n]
(let [
big-p (fn [n]
(let [sn (str n)]
(str sn
(clojure.string/reverse sn))))
small-p (fn [n]
(let [sn (str n)
l (count sn)
bar-last (apply str (take (dec l) sn))]
(str bar-last
(str (last sn))
(clojure.string/reverse bar-last))))
ten-to-the
(fn [n]
(bigint (apply str (cons "1" (repeat n "0")))))
pals-from-n
(fn [n]
(let [s (str n)
l (count s)
mid-point (Math/ceil (/ l 2))
start (bigint (apply str (take mid-point s)))
f (if (even? l)
big-p
small-p)]
(map (comp bigint f)
(range start (ten-to-the mid-point)))))
w-pals
(fn [w]
(pals-from-n (ten-to-the (dec w))))
]
(drop-while
#(< % n)
(concat (pals-from-n n)
(mapcat w-pals
(iterate inc (inc (count (str n)))))))
))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment