Created
September 4, 2017 01:02
-
-
Save tnoborio/e7339074288e133cda66bcc38c4437f5 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
(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