Skip to content

Instantly share code, notes, and snippets.

@tnoborio
Created September 4, 2017 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tnoborio/e7339074288e133cda66bcc38c4437f5 to your computer and use it in GitHub Desktop.
Save tnoborio/e7339074288e133cda66bcc38c4437f5 to your computer and use it in GitHub Desktop.
(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