(ns adventofcode2019.day08 [:require [adventofcode2019.lib :refer :all] [clojure.string :as str] [clojure.core.match :refer [match]]]) (defn day08 [] (let [input (map parse-int (get-list-from-file (input-file) #"")) [image-x image-y] [25 6] layer-size (* image-x image-y) count-num #(count (filter (hash-set %1) %2)) combine-layers #(match [%1 %2] [0 _] 0 [1 _] 1 [2 p] p) to-text #(match % 0 \u0020 ; 0s are spaces, 1s are full-block 1 \u2588) layers (partition layer-size input) fewest-zeroes (apply (partial min-key (partial count-num 0)) layers) layered-image (reduce #(map combine-layers %1 %2) layers)] (part1 (* (count-num 1 fewest-zeroes) (count-num 2 fewest-zeroes))) (part2 "see below") (run! println (->> layered-image (map to-text) (partition image-x) (map str/join)))))