Created
May 15, 2010 18:50
-
-
Save tcrayford/402335 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(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