2 [:require [clojure.string :as str]])
4 (def get-list-from-file
5 #(str/split #"," (slurp %)))
10 (def opcodes {1 +, 2 *})
11 (defn perform-operation [[opcode fst snd thd] program]
12 (let [opcode-fn (opcodes opcode)
14 snd-val (program snd)]
15 (assoc program thd (opcode-fn fst-val snd-val))))
17 (defn intcode [program]
18 (loop [program program
20 (let [opcode (program counter)]
23 (recur (perform-operation (map program (take 4 (iterate inc counter)))
28 (let [input (mapv parse-int (get-list-from-file "input"))
29 fixed-input (assoc input 1 12 2 1)]
30 (println (first (intcode fixed-input)))))