about summary refs log tree commit diff
path: root/day07.clj
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2020-12-08 17:40:58 +0100
committerLeah Neukirchen <leah@vuxu.org>2020-12-08 17:40:58 +0100
commit994a71edcd0353bddf71008fd5599c97098a966c (patch)
treec71996a69f18455e2cdc625f4d69885c428f790a /day07.clj
parentb59e223242a940b435a8badaffe0130836459a10 (diff)
downloadadventofcode2020-994a71edcd0353bddf71008fd5599c97098a966c.tar.gz
adventofcode2020-994a71edcd0353bddf71008fd5599c97098a966c.tar.xz
adventofcode2020-994a71edcd0353bddf71008fd5599c97098a966c.zip
day07
Diffstat (limited to 'day07.clj')
-rw-r--r--day07.clj23
1 files changed, 23 insertions, 0 deletions
diff --git a/day07.clj b/day07.clj
new file mode 100644
index 0000000..255ffeb
--- /dev/null
+++ b/day07.clj
@@ -0,0 +1,23 @@
+(defn parse [l]
+  (let [words (clojure.string/split l #" ")
+        x (str (words 0) " " (words 1))
+        y (map (fn [[n a b _]] [(Integer/parseInt n) (str a " " b)])
+                (partition 4 (drop 4 words)))]
+    {x y}))
+
+(def data
+  (->> (slurp "day07")
+       (clojure.string/split-lines)
+       (map parse)
+       (into {})))
+
+(defn trav [b]
+  (or (= b "shiny gold")
+      (some trav (map second (data b)))))
+
+(dec (count (filter trav (keys d)))) ; => 278
+
+(defn sumup [b]
+  (inc (apply + (map (fn [[n x]] (* n (sumup x))) (data b)))))
+
+(dec (sumup "shiny gold")) ; => 45157