about summary refs log tree commit diff
path: root/day25.clj
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2021-12-25 17:52:09 +0100
committerLeah Neukirchen <leah@vuxu.org>2021-12-25 17:52:09 +0100
commit34dd965131a4e776113f7684a251819239bdf72c (patch)
tree4b3b730f6234fd205f6b07f4d60e87150684cc37 /day25.clj
parentceb09f9791e37f5c7fc422c9f848de09d58a7337 (diff)
downloadadventofcode2021-34dd965131a4e776113f7684a251819239bdf72c.tar.gz
adventofcode2021-34dd965131a4e776113f7684a251819239bdf72c.tar.xz
adventofcode2021-34dd965131a4e776113f7684a251819239bdf72c.zip
day25 HEAD master
Diffstat (limited to 'day25.clj')
-rw-r--r--day25.clj48
1 files changed, 48 insertions, 0 deletions
diff --git a/day25.clj b/day25.clj
new file mode 100644
index 0000000..6489d9c
--- /dev/null
+++ b/day25.clj
@@ -0,0 +1,48 @@
+(ns org.vuxu.aoc2021.day25
+  (:require [clojure.string :as str]))
+
+(def data
+  (->> (slurp "day25")
+       str/split-lines
+       (mapv (partial mapv identity))))
+
+(defn step-east [data]
+  (let [lx (count (first data))]
+    (vec (for [y (range (count data))]
+           (vec (for [x (range lx)]
+                  (cond
+                    (and (= (get-in data [y (mod (dec x) lx)]) \>)
+                         (= (get-in data [y x]) \.))
+                    \>
+
+                    (and (= (get-in data [y x]) \>)
+                         (= (get-in data [y (mod (inc x) lx)]) \.))
+                    \.
+
+                    :else
+                    (get-in data [y x]))))))))
+
+(defn step-south [data]
+  (let [ly (count data)]
+    (vec (for [y (range ly)]
+           (vec (for [x (range (count (first data)))]
+                  (cond
+                    (and (= (get-in data [(mod (dec y) ly) x]) \v)
+                         (= (get-in data [y x]) \.))
+                    \v
+
+                    (and (= (get-in data [y x]) \v)
+                         (= (get-in data [(mod (inc y) ly) x]) \.))
+                    \.
+
+                    :else
+                    (get-in data [y x]))))))))
+
+(def part1
+  (loop [i 1
+         data data]
+    (let [data' (step-south (step-east data))]
+      (if (= data data')
+        i
+        (recur (inc i) data')))))
+;; => 601