Skip to content

Instantly share code, notes, and snippets.

@tcrayford
Created May 15, 2010 18:50
Show Gist options
  • Save tcrayford/402335 to your computer and use it in GitHub Desktop.
Save tcrayford/402335 to your computer and use it in GitHub Desktop.
(defn reverse-int
"Returns an integer with its digits reversed, e.g. 123 returns 321"
[x]
(BigInteger. (su/reverse (pr-str x))))
(defn palindromic?
"Returns true if the number is palindromic, e.g. 121, 1234321"
[x]
(= x (reverse-int x)))
(defn lychrel?
([x] (lychrel? x 50))
([x iterations]
(let [next-num #(+ % (reverse-int %))]
(->> x
(iterate next-num)
rest
(take iterations)
(some palindromic?)
not))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment