From: Jack Kinsey Date: Mon, 2 Dec 2019 15:49:59 +0000 (-0500) Subject: Add untested day 2 pt 1 solution X-Git-Url: http://git.jkinsey.net/?a=commitdiff_plain;h=60ac9869e41809ca418d1e7bc237ee6f5674dd4d;p=adventofcode2019.git Add untested day 2 pt 1 solution --- diff --git a/day02/intcode.clj b/day02/intcode.clj new file mode 100644 index 0000000..f6e5666 --- /dev/null +++ b/day02/intcode.clj @@ -0,0 +1,32 @@ +(ns aoc.core + [:require [clojure.string :as str]]) + +(def get-list-from-file + #(str/split #"," (slurp %))) + +(def parse-int + #(Integer/parseInt %)) + +(def opcodes {1 +, 2 *}) +(defn perform-operation [[opcode fst snd thd] program] + (let [opcode-fn (opcodes opcode) + fst-val (program fst) + snd-val (program snd)] + (assoc program thd (opcode-fn fst-val snd-val)))) + +(defn intcode [program counter] + (loop [program program + counter counter] + (let [opcode (program counter)] + (if (= opcode 99) + program + (recur (perform-operation (map program (take 4 (iterate inc counter))) + program) + (+ counter 4)))))) + +(defn -main [] + (let [input (mapv parse-int (get-list-from-file "input")) + fixed-input (assoc input 1 12 2 1)] + (println (first (intcode fixed-input))))) + +(-main)