From aa5ca3ab7ce773b321821e1b9f3a99344725dee2 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 20 Dec 2021 12:24:12 -0500 Subject: day20: forgot to put into folder --- day20/partboth.clj | 44 ++++++++++++++++++++++++++++++++++++++++++++ partboth.clj | 44 -------------------------------------------- 2 files changed, 44 insertions(+), 44 deletions(-) create mode 100644 day20/partboth.clj delete mode 100644 partboth.clj diff --git a/day20/partboth.clj b/day20/partboth.clj new file mode 100644 index 0000000..4e460ca --- /dev/null +++ b/day20/partboth.clj @@ -0,0 +1,44 @@ +(require '[clojure.string :as str]) + +(defn pad-input-map [in-map pad-val] + (let [pad-row (repeat (+ 4 (count (first in-map))) pad-val) + pad-side (repeat 2 pad-val)] + (mapv vec + (concat + [pad-row pad-row] + (mapv #(concat pad-side % pad-side) in-map) + [pad-row pad-row])))) + +(defn get-number [in-map y x] + (concat (subvec (get in-map (dec y)) (dec x) (+ 2 x)) + (subvec (get in-map y) (dec x) (+ 2 x)) + (subvec (get in-map (inc y)) (dec x) (+ 2 x)))) + +(defn get-new-pixel [enhance-algo in-map y x] + (->> (get-number in-map y x) + str/join + (#(Integer/parseInt % 2)) + (get enhance-algo) + {\. 0 \# 1})) + +(defn build-output-number-map [enhance-algo in-map] + (let [pad-val (if (= \# (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)))] + (for [x (range 1 (dec (count (first padded-in-map))))] + (get-new-pixel enhance-algo padded-in-map y x) + )))) + +(defn count-lit-pixels [in-map] + ((frequencies (flatten in-map)) 1)) + +(let [[enhance-algo in-map] + (->> (slurp "./in") + str/split-lines + ((juxt + first + (comp (partial mapv #(mapv {\. 0 \# 1} %)) + (partial drop 2))))) + image-output (iterate (partial build-output-number-map enhance-algo) in-map)] + (println (count-lit-pixels (nth image-output 50)))) + diff --git a/partboth.clj b/partboth.clj deleted file mode 100644 index 4e460ca..0000000 --- a/partboth.clj +++ /dev/null @@ -1,44 +0,0 @@ -(require '[clojure.string :as str]) - -(defn pad-input-map [in-map pad-val] - (let [pad-row (repeat (+ 4 (count (first in-map))) pad-val) - pad-side (repeat 2 pad-val)] - (mapv vec - (concat - [pad-row pad-row] - (mapv #(concat pad-side % pad-side) in-map) - [pad-row pad-row])))) - -(defn get-number [in-map y x] - (concat (subvec (get in-map (dec y)) (dec x) (+ 2 x)) - (subvec (get in-map y) (dec x) (+ 2 x)) - (subvec (get in-map (inc y)) (dec x) (+ 2 x)))) - -(defn get-new-pixel [enhance-algo in-map y x] - (->> (get-number in-map y x) - str/join - (#(Integer/parseInt % 2)) - (get enhance-algo) - {\. 0 \# 1})) - -(defn build-output-number-map [enhance-algo in-map] - (let [pad-val (if (= \# (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)))] - (for [x (range 1 (dec (count (first padded-in-map))))] - (get-new-pixel enhance-algo padded-in-map y x) - )))) - -(defn count-lit-pixels [in-map] - ((frequencies (flatten in-map)) 1)) - -(let [[enhance-algo in-map] - (->> (slurp "./in") - str/split-lines - ((juxt - first - (comp (partial mapv #(mapv {\. 0 \# 1} %)) - (partial drop 2))))) - image-output (iterate (partial build-output-number-map enhance-algo) in-map)] - (println (count-lit-pixels (nth image-output 50)))) - -- cgit v1.2.3