From 994a71edcd0353bddf71008fd5599c97098a966c Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Tue, 8 Dec 2020 17:40:58 +0100 Subject: day07 --- day07.clj | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 day07.clj (limited to 'day07.clj') 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 -- cgit 1.4.1