Last active
June 25, 2016 09:11
-
-
Save athos/59a0f3651b8f2d847aa49be620d340f3 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
(def actions | |
(repeatedly (read) (fn [] [(read) (read)]))) | |
(defn step [[[[t op] & as' :as as] temp temps] time] | |
(let [temp' (+ temp (if (= time t) (get '{out 3 in 5} op) 0))] | |
[(if (= time t) as' as), (max (dec temp') 0), (conj temps temp')])) | |
(defn calc [actions] | |
(let [zs (count (filter zero? (last (reduce step [actions 0 []] (range 24)))))] | |
(+ zs (* 2 (- 24 zs))))) | |
(println (calc actions)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment