projects
/
adventofcode2019.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
4ddb1aa
)
Tidy up day8 a little bit
author
Jack Kinsey
<j.jameskinsey@gmail.com>
Sun, 8 Dec 2019 19:08:15 +0000
(14:08 -0500)
committer
Jack Kinsey
<j.jameskinsey@gmail.com>
Sun, 8 Dec 2019 19:08:15 +0000
(14:08 -0500)
src/adventofcode2019/day08.clj
patch
|
blob
|
blame
|
history
diff --git
a/src/adventofcode2019/day08.clj
b/src/adventofcode2019/day08.clj
index a3aa45e77f86734723fcd7c44010f03f2c637f35..d27d718031b84bb226bf5b5e10ae28ab93aa2302 100644
(file)
--- a/
src/adventofcode2019/day08.clj
+++ b/
src/adventofcode2019/day08.clj
@@
-1,25
+1,27
@@
(ns adventofcode2019.day08
[:require [adventofcode2019.lib :refer :all]
(ns adventofcode2019.day08
[:require [adventofcode2019.lib :refer :all]
+ [clojure.string :as str]
[clojure.core.match :refer [match]]])
[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 []
(defn day08 []
- (let [input (mapv parse-int (get-list-from-file (input-file) #""))
- layer-size (* 25 6)
+ (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))
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)
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)]
+
+ 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")
(part1 (* (count-num 1 fewest-zeroes)
(count-num 2 fewest-zeroes)))
(part2 "see below")
- (run! println (partition 25 (map to-ascii layered-image)))))
+ (run! println (->> layered-image
+ (map to-text)
+ (partition image-x)
+ (map str/join)))))