Skip to content

Instantly share code, notes, and snippets.

@athos
Last active June 25, 2016 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save athos/59a0f3651b8f2d847aa49be620d340f3 to your computer and use it in GitHub Desktop.
Save athos/59a0f3651b8f2d847aa49be620d340f3 to your computer and use it in GitHub Desktop.
(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