From 34dd965131a4e776113f7684a251819239bdf72c Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Sat, 25 Dec 2021 17:52:09 +0100 Subject: day25 --- day25.clj | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 day25.clj (limited to 'day25.clj') 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 -- cgit 1.4.1