about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2021-12-13 18:00:22 +0100
committerLeah Neukirchen <leah@vuxu.org>2021-12-13 18:00:22 +0100
commit9ffcaa96c6e89319d62402432461aa5c2ed4c145 (patch)
tree8f2a0f9b472349df65e8bff22b005d39a66f58e5
parent5ff78d12414b9c756fab419896cbc4d561188080 (diff)
downloadadventofcode2021-9ffcaa96c6e89319d62402432461aa5c2ed4c145.tar.gz
adventofcode2021-9ffcaa96c6e89319d62402432461aa5c2ed4c145.tar.xz
adventofcode2021-9ffcaa96c6e89319d62402432461aa5c2ed4c145.zip
day12
-rw-r--r--day1224
-rw-r--r--day12.clj38
2 files changed, 62 insertions, 0 deletions
diff --git a/day12 b/day12
new file mode 100644
index 0000000..fbb547b
--- /dev/null
+++ b/day12
@@ -0,0 +1,24 @@
+yb-start
+de-vd
+rj-yb
+rj-VP
+OC-de
+MU-de
+end-DN
+vd-end
+WK-vd
+rj-de
+DN-vd
+start-VP
+DN-yb
+vd-MU
+DN-rj
+de-VP
+yb-OC
+start-rj
+oa-MU
+yb-de
+oa-VP
+jv-MU
+yb-MU
+end-OC
diff --git a/day12.clj b/day12.clj
new file mode 100644
index 0000000..15267fb
--- /dev/null
+++ b/day12.clj
@@ -0,0 +1,38 @@
+(ns org.vuxu.aoc2021.day12
+  (:require [clojure.string :as str]))
+
+(def data
+  (->> (slurp "day12")
+       (str/split-lines)
+       (map #(str/split % #"-"))))
+
+(def datamap
+  (update-vals
+   (group-by first
+             (concat
+              (map (comp vec reverse) data)
+              data))
+   #(set (mapv second %))))
+
+(defn dfs [path repeat?]
+  (if (= (last path) "end")
+    1
+    (apply + (for [n (datamap (last path))]
+               (cond (not (and (Character/isLowerCase (first n))
+                               (some #{n} path)))
+                     (dfs (conj path n) repeat?)
+
+                     (and repeat?
+                          (= (count (filter #{n} path)) 1)
+                          (not= n "start"))
+                     (dfs (conj path n) false)
+
+                     :else 0)))))
+
+(def part1
+  (dfs ["start"] false))
+;; => 4411      
+
+(def part2
+  (dfs2 ["start"] true))
+;; => 136767