Commit | Line | Data |
---|---|---|
4ddb1aae JK |
1 | (ns adventofcode2019.day08 |
2 | [:require [adventofcode2019.lib :refer :all] | |
3 | [clojure.core.match :refer [match]]]) | |
4 | ||
5 | (def combine-layers | |
6 | "Binary operation on the pixels of two layers, the first above the second." | |
7 | #(match [%1 %2] | |
8 | [0 _] 0 | |
9 | [1 _] 1 | |
10 | [2 p] p)) | |
11 | ||
12 | (defn day08 [] | |
13 | (let [input (mapv parse-int (get-list-from-file (input-file) #"")) | |
14 | layer-size (* 25 6) | |
15 | count-num #(count (filter (hash-set %1) %2)) | |
16 | layers (partition layer-size input) | |
17 | fewest-zeroes (apply (partial min-key (partial count-num 0)) | |
18 | layers) | |
19 | layered-image (reduce #(mapv combine-layers %1 %2) layers) | |
20 | to-ascii #(match % 0 \u0020 ; 0s are spaces, 1s are full-block | |
21 | 1 \u2588)] | |
22 | (part1 (* (count-num 1 fewest-zeroes) | |
23 | (count-num 2 fewest-zeroes))) | |
24 | (part2 "see below") | |
25 | (run! println (partition 25 (map to-ascii layered-image))))) |