From 8d43e37df99f280377bed90284d6ac2428334804 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 30 Nov 2022 19:55:31 -0500 Subject: move 2021 days to folder; update README --- day11/part1.clj | 41 ----------------------------------------- day11/part2.clj | 42 ------------------------------------------ 2 files changed, 83 deletions(-) delete mode 100644 day11/part1.clj delete mode 100644 day11/part2.clj (limited to 'day11') diff --git a/day11/part1.clj b/day11/part1.clj deleted file mode 100644 index 5113fd4..0000000 --- a/day11/part1.clj +++ /dev/null @@ -1,41 +0,0 @@ -(defn get-adj [in y x] - (filter - #(some? (get-in in %)) - [[(dec y) (dec x)] [(dec y) x] [(dec y) (inc x)] - [y (dec x)] [y (inc x)] - [(inc y) (dec x)] [(inc y) x] [(inc y) (inc x)]] - )) - -(defn apply-incs [in] (mapv (partial mapv inc) in)) - -(defn next-step [indata] - (loop [in (apply-incs (indata :grid)) bl (indata :blinks) y 0 x 0] - (cond - (> (get-in in [y x]) 9) - (do - (recur - (-> (reduce - (fn [i n] (update-in i n #(cond-> % (pos? %) inc))) - in - (get-adj in y x)) - (update-in [y x] #(do % 0))) - (inc bl) - 0 0)) - (< x (dec (count (first in)))) - (recur in bl y (inc x)) - (< y (dec (count in))) - (recur in bl (inc y) 0) - :else - {:grid in :blinks bl} - ) - ) - ) - -(->> (slurp "./in") - (clojure.string/split-lines) - (map (partial map #(- (int %) 48))) - (assoc {} :blinks 0 :grid) - (iterate next-step) - (#(nth % 100)) - (#(println (% :blinks)))) - diff --git a/day11/part2.clj b/day11/part2.clj deleted file mode 100644 index 4c4663c..0000000 --- a/day11/part2.clj +++ /dev/null @@ -1,42 +0,0 @@ -(defn get-adj [in y x] - (filter - #(some? (get-in in %)) - [[(dec y) (dec x)] [(dec y) x] [(dec y) (inc x)] - [y (dec x)] [y (inc x)] - [(inc y) (dec x)] [(inc y) x] [(inc y) (inc x)]] - )) - -(defn apply-incs [in] (mapv (partial mapv inc) in)) - -(defn next-step [indata] - (loop [in (apply-incs (indata :grid)) bl (indata :blinks) y 0 x 0] - (cond - (> (get-in in [y x]) 9) - (do - (recur - (-> (reduce - (fn [i n] (update-in i n #(cond-> % (pos? %) inc))) - in - (get-adj in y x)) - (update-in [y x] #(do % 0))) - (inc bl) - 0 0)) - (< x (dec (count (first in)))) - (recur in bl y (inc x)) - (< y (dec (count in))) - (recur in bl (inc y) 0) - :else - {:grid in :blinks bl} - ) - ) - ) - -(->> (slurp "./in") - (clojure.string/split-lines) - (map (partial map #(- (int %) 48))) - (assoc {} :blinks 0 :grid) - (iterate next-step) - (take-while #(pos? (apply + (flatten (% :grid))))) - (count) - (println)) - -- cgit v1.2.3