From 60ac9869e41809ca418d1e7bc237ee6f5674dd4d Mon Sep 17 00:00:00 2001 From: Jack Kinsey Date: Mon, 2 Dec 2019 10:49:59 -0500 Subject: [PATCH] Add untested day 2 pt 1 solution --- day02/intcode.clj | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 day02/intcode.clj 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) -- 2.26.2