Created
July 9, 2014 06:42
-
-
Save shanemhansen/b237c8ebc747cc6e0ed2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Foo | |
(:gen-class)) | |
(defn tick [[queue rung1 rung2 rung3]] | |
(let [ball (first queue) queue (rest queue)] | |
(if (not= (count rung1) 4) | |
[queue (cons ball rung1) rung2 rung3] | |
(let [queue (concat queue rung1) rung1 ()] | |
(if (not= (count rung2) 11) | |
[queue rung1 (cons ball rung2) rung3] | |
(let [queue (concat queue rung2) rung2 ()] | |
(if (not= (count rung3) 11) | |
[queue rung1 rung2 (cons ball rung3)] | |
[(concat queue rung3 [ball]) rung1 rung2 ()] | |
))))))) | |
(defn minutes-to-days [minutes] | |
(int (/ minutes (* 60 24)))) | |
(defn period [[queue rung1 rung2 rung3]] | |
(inc (count (take-while #(not= queue (get % 0)) (iterate tick (tick [queue rung1 rung2 rung3])))))) | |
(defn -main | |
"I don't do a whole lot." | |
[cnt & args] | |
(def queue (range 0 (Integer/parseInt cnt))) | |
(def rung1 ()) | |
(def rung2 ()) | |
(def rung3 ()) | |
(time (doseq [i (range 0 10)] | |
(let [days (minutes-to-days (period [queue rung1 rung2 rung3]))] | |
(println (count queue) "balls cycle in" days "days"))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment