-
-
Save tomjack/1b2c0b1a7fb5807caa3d 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
(defn digits | |
([n] (digits n [])) | |
([n acc] | |
(if (== n 0) | |
acc | |
(recur (int (/ n 10)) | |
(conj acc (mod n 10)))))) | |
(defn next-num [n] | |
(reduce + (map #(* % %) (digits n)))) | |
(defn chain-end [n] | |
(if (or (== n 89) (== n 1)) | |
n | |
(chain-end (next-num n)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment