]> localhost Git - adventofcode2019.git/blame - src/adventofcode2019/day08.clj
Add extremely broken day14pt2
[adventofcode2019.git] / src / adventofcode2019 / day08.clj
CommitLineData
4ddb1aae
JK
1(ns adventofcode2019.day08
2 [:require [adventofcode2019.lib :refer :all]
103ead17 3 [clojure.string :as str]
4ddb1aae
JK
4 [clojure.core.match :refer [match]]])
5
4ddb1aae 6(defn day08 []
103ead17
JK
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
4ddb1aae 11 count-num #(count (filter (hash-set %1) %2))
103ead17
JK
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)
4ddb1aae 17 layers (partition layer-size input)
103ead17
JK
18
19 fewest-zeroes (apply (partial min-key (partial count-num 0)) layers)
20 layered-image (reduce #(map combine-layers %1 %2) layers)]
4ddb1aae
JK
21 (part1 (* (count-num 1 fewest-zeroes)
22 (count-num 2 fewest-zeroes)))
23 (part2 "see below")
103ead17
JK
24 (run! println (->> layered-image
25 (map to-text)
26 (partition image-x)
27 (map str/join)))))