]>
Commit | Line | Data |
---|---|---|
1 | (ns adventofcode2019.day08 | |
2 | [:require [adventofcode2019.lib :refer :all] | |
3 | [clojure.string :as str] | |
4 | [clojure.core.match :refer [match]]]) | |
5 | ||
6 | (defn day08 [] | |
7 | (let [input (map parse-int (get-list-from-file (input-file) #"")) | |
8 | [image-x image-y] [25 6] | |
9 | layer-size (* image-x image-y) | |
10 | ||
11 | count-num #(count (filter (hash-set %1) %2)) | |
12 | combine-layers #(match [%1 %2] [0 _] 0 | |
13 | [1 _] 1 | |
14 | [2 p] p) | |
15 | to-text #(match % 0 \u0020 ; 0s are spaces, 1s are full-block | |
16 | 1 \u2588) | |
17 | layers (partition layer-size input) | |
18 | ||
19 | fewest-zeroes (apply (partial min-key (partial count-num 0)) layers) | |
20 | layered-image (reduce #(map combine-layers %1 %2) layers)] | |
21 | (part1 (* (count-num 1 fewest-zeroes) | |
22 | (count-num 2 fewest-zeroes))) | |
23 | (part2 "see below") | |
24 | (run! println (->> layered-image | |
25 | (map to-text) | |
26 | (partition image-x) | |
27 | (map str/join))))) |