about summary refs log tree commit diff
path: root/day07.clj
blob: 255ffebc61bf5c28a8c9631534e69fa60a2207c4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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