1 (ns adventofcode2019.day02
2 [:require [adventofcode2019.lib :refer :all]
3 [clojure.string :as str]
4 [clojure.math.combinatorics :as combo]])
6 (def opcodes {1 +, 2 *})
7 (defn perform-operation [[opcode fst snd thd] program]
8 (let [opcode-fn (opcodes opcode)
10 snd-val (program snd)]
11 (assoc program thd (opcode-fn fst-val snd-val))))
13 (defn intcode [program]
14 (loop [program program
16 (let [opcode (program counter)]
19 (recur (perform-operation (map program (take 4 (iterate inc counter)))
23 (defn check-inputs [input noun verb]
24 (let [fixed-input (assoc input 1 noun 2 verb)]
25 (first (intcode fixed-input))))
28 (let [input (mapv parse-int (get-list-from-file (input-file) #","))
29 [noun verb] (first (filter (fn [[noun verb]] (= (check-inputs input noun verb) 19690720))
30 (combo/cartesian-product (range 100) (range 100))))]
31 (println (check-inputs input 12 2)) ;; part 1
32 (println (+ (* 100 noun) verb)))) ;; part 2