diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2022-11-30 19:55:31 -0500 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2022-11-30 19:55:31 -0500 |
commit | 8d43e37df99f280377bed90284d6ac2428334804 (patch) | |
tree | 3a5042c9af29da52b4bac38fd78b3ccde77a1dbc /day13 | |
parent | 66ed0b9d27850dc653abc8baa75884f3de311bfa (diff) |
move 2021 days to folder; update README
Diffstat (limited to 'day13')
-rw-r--r-- | day13/part1.clj | 30 | ||||
-rw-r--r-- | day13/part2.clj | 33 | ||||
-rw-r--r-- | day13/partboth.clj | 49 |
3 files changed, 0 insertions, 112 deletions
diff --git a/day13/part1.clj b/day13/part1.clj deleted file mode 100644 index c3f08d4..0000000 --- a/day13/part1.clj +++ /dev/null @@ -1,30 +0,0 @@ -(require '[clojure.string :as str]) - -(def input (->> (slurp "./in") - (str/split-lines) - (split-with not-empty) - ((juxt - (fn [lst] - (reduce - #(conj %1 (mapv read-string (str/split %2 #","))) - #{} (first lst))) - (fn [lst] - (->> (second lst) - (drop 1) - (map #(-> % - (str/split #"=") - (update 0 (comp {\x 0 \y 1} last)) - (update 1 read-string))) - (first) - )))))) - -(defn fold-point [idx chg pt] - (cond-> pt (> (get pt idx) chg) (update idx #(- % (* 2 (- % chg)))))) - -(let [instruction (second input)] - (->> (first input) - (map (partial fold-point (first instruction) (second instruction))) - (distinct) - (count) - (println))) - diff --git a/day13/part2.clj b/day13/part2.clj deleted file mode 100644 index 6db6555..0000000 --- a/day13/part2.clj +++ /dev/null @@ -1,33 +0,0 @@ -(require '[clojure.string :as str]) - -(def input (->> (slurp "./in") - (str/split-lines) - (split-with not-empty) - ((juxt - (fn [lst] - (reduce - #(conj %1 (mapv read-string (str/split %2 #","))) - #{} (first lst))) - (fn [lst] - (->> (rest (second lst)) - (map #(-> % - (str/split #"=") - (update 0 (comp {\x 0 \y 1} last)) - (update 1 read-string))) - )))))) - -(defn print-grid [pts] - (doseq [p pts] (println (str/join [(first p) "," (second p)])))) - -(defn fold-point [idx chg pt] - (cond-> pt (> (get pt idx) chg) (update idx #(- % (* 2 (- % chg)))))) - -(print-grid - (apply - (partial - reduce - #(let [ins (first %2)] - (set (map (partial fold-point (first %2) (second %2)) %1)))) - input - )) - diff --git a/day13/partboth.clj b/day13/partboth.clj deleted file mode 100644 index c24980d..0000000 --- a/day13/partboth.clj +++ /dev/null @@ -1,49 +0,0 @@ -(require '[clojure.string :as str]) - -(def input (->> (slurp "./in") - (str/split-lines) - (split-with not-empty) - ((juxt - (fn [lst] - (reduce - #(conj %1 (mapv read-string (str/split %2 #","))) - #{} (first lst))) - (fn [lst] - (->> (second lst) - (drop 1) - (map #(-> % - (str/split #"=") - (update 0 (comp {\x 0 \y 1} last)) - (update 1 read-string))) - )))))) - -(defn fold-point [idx chg pt] - (cond-> pt (> (get pt idx) chg) (update idx #(- % (* 2 (- % chg)))))) - -(defn print-grid [pts] - (let [xmax (inc (apply max (map first pts))) - ymax (inc (apply max (map second pts)))] - (doseq [y (range 0 ymax)] - (println - (str/join - (for [x (range 0 xmax)] (if (contains? pts [x y]) \@ \ )) - ))))) - -; Part 1 -(let [instruction (first (second input))] - (->> (first input) - (map (partial fold-point (first instruction) (second instruction))) - (distinct) - (count) - (println))) - -; Part 2 -(print-grid - (apply - (partial - reduce - #(let [ins (first %2)] - (set (map (partial fold-point (first %2) (second %2)) %1)))) - input - )) - |