Skip to content

Instantly share code, notes, and snippets.

@tomjack

tomjack/92.clj Secret

Created October 29, 2009 04:17
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 tomjack/1b2c0b1a7fb5807caa3d to your computer and use it in GitHub Desktop.
Save tomjack/1b2c0b1a7fb5807caa3d to your computer and use it in GitHub Desktop.
(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