From 2cea1afcc8190f0c8ec036ca998f23e5fef77bf2 Mon Sep 17 00:00:00 2001 From: Adam Jeniski Date: Tue, 16 Jan 2024 20:59:52 -0500 Subject: [PATCH] day21 part 1 --- 2023/src/day21.clj | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 2023/src/day21.clj diff --git a/2023/src/day21.clj b/2023/src/day21.clj new file mode 100644 index 0000000..9033ffc --- /dev/null +++ b/2023/src/day21.clj @@ -0,0 +1,34 @@ +(ns day21 + (:require + [core :refer [get-puzzle-input]])) + +(def input (get-puzzle-input 21)) +(def char-map (->> input + (map-indexed (fn [row line] + (map-indexed (fn [col c] + [[row col] c]) + line))) + (apply concat) + (into {}))) +(def start (->> char-map + (filter #(= \S (second %))) + ffirst)) +(def offsets [[0 1] [0 -1] [1 0] [-1 0]]) + +;; part 1 +(loop [locs #{start} + n 0] + (if (< n 64) + (recur (->> locs + (map (fn [[x y]] + (map (fn [[x-off y-off]] + [(+ x x-off) + (+ y y-off)]) + offsets))) + (apply concat) + (filter #(not= (char-map %) + \#)) + (into #{})) + (inc n)) + (count locs))) +