aboutsummaryrefslogtreecommitdiffstats
path: root/day20
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2022-11-30 19:55:31 -0500
committerClyne Sullivan <clyne@bitgloo.com>2022-11-30 19:55:31 -0500
commit8d43e37df99f280377bed90284d6ac2428334804 (patch)
tree3a5042c9af29da52b4bac38fd78b3ccde77a1dbc /day20
parent66ed0b9d27850dc653abc8baa75884f3de311bfa (diff)
move 2021 days to folder; update README
Diffstat (limited to 'day20')
-rw-r--r--day20/partboth.clj43
1 files changed, 0 insertions, 43 deletions
diff --git a/day20/partboth.clj b/day20/partboth.clj
deleted file mode 100644
index 33a4d4f..0000000
--- a/day20/partboth.clj
+++ /dev/null
@@ -1,43 +0,0 @@
-(require '[clojure.string :as str])
-
-(defn pad-input-map [in-map pad-val]
- (let [ly (count in-map) lx (count (first in-map))
- sy (+ 4 ly) sx (+ 4 lx)
- buffer (byte-array (repeat (* sy sx) pad-val))]
- (doseq [y (range 0 ly) x (range 0 lx)]
- (aset-byte buffer (+ (* sx (+ 2 y)) 2 x) (get-in in-map [y x])))
- (mapv vec (partition sx buffer))))
-
-(defn get-number [in-map y x]
- (map (partial get-in in-map)
- [[(dec y) (dec x)] [(dec y) x] [(dec y) (inc x)]
- [y (dec x)] [y x] [y (inc x)]
- [(inc y) (dec x)] [(inc y) x] [(inc y) (inc x)]]))
-
-(defn get-new-pixel [enhance-algo in-map y x]
- (->> (get-number in-map y x)
- (reduce #(cond-> (* 2 %1) (= 1 %2) inc) 0)
- (get enhance-algo)))
-
-(defn build-output-number-map [enhance-algo in-map]
- (let [pad-val (if (pos? (first enhance-algo)) (first (first in-map)) 0)
- padded-in-map (pad-input-map in-map pad-val)]
- (->> (for [y (range 1 (dec (count padded-in-map)))]
- (future
- (mapv (partial get-new-pixel enhance-algo padded-in-map y)
- (range 1 (dec (count (first padded-in-map)))))))
- (mapv deref))))
-
-(defn count-lit-pixels [in-map] ((frequencies (flatten in-map)) 1))
-
-(let [[enhance-algo in-map]
- (->> (slurp "./in")
- str/split-lines
- ((juxt (comp (partial mapv {\. 0 \# 1}) first)
- (comp (partial mapv #(mapv {\. 0 \# 1} %)) (partial drop 2)))))
- image-output (iterate (partial build-output-number-map enhance-algo) in-map)]
- (println "Part 1:" (count-lit-pixels (nth image-output 2)))
- (println "Part 2:" (count-lit-pixels (nth image-output 50))))
-
-(shutdown-agents)
-