(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)))))