From 15f6c3bbb172e88ff9a6d393057abc40db9373bf Mon Sep 17 00:00:00 2001 From: Jack Kinsey Date: Fri, 13 Dec 2019 13:52:51 -0500 Subject: [PATCH] Add untested day13pt1 --- src/adventofcode2019/core.clj | 2 +- src/adventofcode2019/day13.clj | 14 ++++++++++++++ src/adventofcode2019/intcode.clj | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/adventofcode2019/day13.clj diff --git a/src/adventofcode2019/core.clj b/src/adventofcode2019/core.clj index c2d5b25..ca8684b 100644 --- a/src/adventofcode2019/core.clj +++ b/src/adventofcode2019/core.clj @@ -1,7 +1,7 @@ (ns adventofcode2019.core [:require (adventofcode2019 day01 day02 day03 day04 day05 day06 day07 day08 day09 day10 - day11 day12)]) + day11 day12 day13)]) (defn -main ([] diff --git a/src/adventofcode2019/day13.clj b/src/adventofcode2019/day13.clj new file mode 100644 index 0000000..759b3b3 --- /dev/null +++ b/src/adventofcode2019/day13.clj @@ -0,0 +1,14 @@ +(ns adventofcode2019.day13 + [:require [adventofcode2019.lib :refer :all] + [adventofcode2019.intcode :as i] + [clojure.string :as str] + [clojure.core.match :refer [match]] + [clojure.math.combinatorics :as combo]]) + +(defn day13 [] + (let [input (i/get-program (input-file)) + output (:output (i/intcode (i/build-state input))) + draw-tiles (fn [screen [x y t]] (assoc screen [x y] t)) + screen (reduce draw-tiles {} (partition 3 output))] + (part1 (count (filter #(= % 4) (vals screen)))) + #_(part2))) diff --git a/src/adventofcode2019/intcode.clj b/src/adventofcode2019/intcode.clj index 84a9625..9f09f10 100644 --- a/src/adventofcode2019/intcode.clj +++ b/src/adventofcode2019/intcode.clj @@ -61,6 +61,9 @@ args (map memory [(+ 1 ctr) (+ 2 ctr) (+ 3 ctr)])] (apply operation state args))) +(defn get-program [input-file] + (map parse-int (get-list-from-file input-file) #",")) + (defn build-state ([program] (let [memory (into {} (map-indexed #(vector %1 %2) program))] -- 2.38.5