--- /dev/null
+(ns adventofcode2019.day02
+ [:require [adventofcode2019.lib :refer :all]
+ [clojure.string :as str]])
+
+(def operations {1 [#(assoc %4 %3 (+ %1 %2)) 3]
+ 2 [#(assoc %4 %3 (* %1 %2)) 3]
+ 3 [#(do (println (%2 %1)) %2) 1]
+ 4 [#(assoc %2 %1 (parse-int (read-line))) 1]})
+(def decode-op (memoize (fn [opcode]
+ (let [str-code (format "%05d" opcode)
+ [f3 f2 f1] (map #(= \1 %) (take 3 str-code))
+ op (parse-int (str/join (drop 3 str-code)))
+ [operation arg-ct] (operations op)]
+ [(case arg-ct
+ 1 #(operation ((if f1 identity %1) %2) %1)
+ 3 #(operation ((if f1 identity %1) %2)
+ ((if f2 identity %1) %3)
+ ((if f3 identity %1) %4) %1)
+ nil) arg-ct]))))
+
+(defn perform-operation [program counter]
+ (let [opcode (program counter)
+ [operation arg-ct] (decode-op opcode)
+ args (->> (iterate inc counter)
+ (rest)
+ (take arg-ct)
+ (map program))]
+ [(apply operation program args)
+ (+ counter arg-ct 1)]))
+
+(defn intcode [program]
+ (loop [[program counter] [program 0]]
+ (let [opcode (program counter)]
+ (if (= opcode 99)
+ program
+ (recur (perform-operation program counter))))))
+
+(defn day02 []
+ (let [input (mapv parse-int (get-list-from-file (input-file) #","))]
+ (part1 "see below")
+ (intcode input)
+ #_(part2)))