]> code.bitgloo.com Git - clyne/advent-of-code.git/commitdiff
add day 22 part 1
authorClyne Sullivan <clyne@bitgloo.com>
Thu, 23 Dec 2021 00:49:40 +0000 (19:49 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Thu, 23 Dec 2021 00:49:40 +0000 (19:49 -0500)
day22/part1.clj [new file with mode: 0644]

diff --git a/day22/part1.clj b/day22/part1.clj
new file mode 100644 (file)
index 0000000..bffc1a9
--- /dev/null
@@ -0,0 +1,25 @@
+(require '[clojure.string :as str])
+
+(def input (->> (slurp "./in")
+                (str/split-lines)
+                (map
+                  (fn [line]
+                    [(if (str/starts-with? line "on") true false)
+                     (->> (str/split line #"[^-\d]+")
+                          (rest)
+                          (map #(Integer/parseInt %))
+                          (partition 2))]))))
+
+(println
+  (frequencies
+    (vals
+      (reduce
+        (fn [cmap c]
+          (into cmap
+            (let [[xx yy zz] (second c)]
+              (for [x (range (max -50 (first xx)) (inc (min 50 (second xx))))
+                    y (range (max -50 (first yy)) (inc (min 50 (second yy))))
+                    z (range (max -50 (first zz)) (inc (min 50 (second zz))))]
+                [[x y z] (first c)]))))
+        {} input))))
+