]> localhost Git - adventofcode2019.git/commitdiff
Add correct day8pt1, day8pt2
authorJack Kinsey <j.jameskinsey@gmail.com>
Sun, 8 Dec 2019 18:40:08 +0000 (13:40 -0500)
committerJack Kinsey <j.jameskinsey@gmail.com>
Sun, 8 Dec 2019 18:40:08 +0000 (13:40 -0500)
src/adventofcode2019/core.clj
src/adventofcode2019/day08.clj [new file with mode: 0644]
src/adventofcode2019/template.clj

index f4cc833cc3684f101acbe49ff4877fc8fc7ff01e..395bf5ddada82079168fd9ad72f89b4933ab33ba 100644 (file)
@@ -1,7 +1,7 @@
 (ns adventofcode2019.core
     [:require (adventofcode2019 day01 day02 day03
                                 day04 day05 day06
-                                day07)])
+                                day07 day08)])
 
 (defn -main 
   ([]
diff --git a/src/adventofcode2019/day08.clj b/src/adventofcode2019/day08.clj
new file mode 100644 (file)
index 0000000..a3aa45e
--- /dev/null
@@ -0,0 +1,25 @@
+(ns adventofcode2019.day08
+    [:require [adventofcode2019.lib :refer :all]
+              [clojure.core.match :refer [match]]])
+
+(def combine-layers 
+  "Binary operation on the pixels of two layers, the first above the second."
+  #(match [%1 %2]
+          [0 _] 0
+          [1 _] 1
+          [2 p] p))
+
+(defn day08 []
+  (let [input (mapv parse-int (get-list-from-file (input-file) #""))
+        layer-size (* 25 6)
+        count-num #(count (filter (hash-set %1) %2))
+        layers (partition layer-size input)
+        fewest-zeroes (apply (partial min-key (partial count-num 0)) 
+                             layers)
+        layered-image (reduce #(mapv combine-layers %1 %2) layers)
+        to-ascii #(match % 0 \u0020 ; 0s are spaces, 1s are full-block
+                           1 \u2588)] 
+    (part1 (* (count-num 1 fewest-zeroes)
+              (count-num 2 fewest-zeroes)))
+    (part2 "see below")
+    (run! println (partition 25 (map to-ascii layered-image)))))
index 9e8d2b57b2a50a94b3915b0a77453f0d36619db1..c239cb5d8ad2b24848a4eeea2da62b177dd87754 100644 (file)
@@ -6,4 +6,5 @@
 
 (defn day00 []
   (let [input (map parse-int (get-list-from-file (input-file)))] 
-    (comment Your code here!)))
+    #_(part1)
+    #_(part2)))