Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(ns repeating-decimal)
(defn repeating-decimal [n]
(loop [rem 1 rems #{} divs [] i 0]
(let [div (int (/ (* rem 10) n))
rem (mod (* rem 10) n)]
(if (and (not= rem 0) (contains? rems rem))
[n divs]
(when (not= rem 0)
(recur rem (conj rems rem) (conj divs div) (inc i)))))))
(repeating-decimal 7)
(repeating-decimal 11)
(repeating-decimal 12)
(repeating-decimal 97)
(def nums (for [[n qs] (map repeating-decimal (range 1 100001))
:when n]
[n qs]))
(def max-num (last (sort-by second nums)))
(-> max-num first)
(-> max-num second count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment