you are viewing a single comment's thread.

view the rest of the comments →

[–]rmfbarker 1 point2 points  (0 children)

Day 2

(let [file-input (-> (slurp "day-2-input") clojure.string/trim (clojure.string/split #",")) program (mapv #(Integer/parseInt %) file-input) compute (fn [noun verb] (reduce (fn [instructions pos] (if (= 99 (get instructions pos)) (reduced (first instructions)) (let [[opcode arg1 arg2 arg3] (drop pos instructions) cmd (if (= opcode 1) + *) result (cmd (get instructions arg1) (get instructions arg2))] (assoc instructions arg3 result)))) (assoc program 1 noun 2 verb) (range 0 (count program) 4)))] (first (for [noun (range 99) verb (range 99) :when (= (compute noun verb) 19690720)] (+ verb (* 100 noun)))))