Commit | Line | Data |
---|---|---|
c0bc8aca JK |
1 | (ns adventofcode2019.day06 |
2 | [:require [adventofcode2019.lib :refer :all] | |
3 | [clojure.string :as str]]) | |
4 | ||
5 | ;; FIXME: is the input guaranteed in-order? | |
6 | (defn a-orbits-b [orbits-map [b a]] | |
7 | (if (contains? orbits-map b) | |
8 | (-> (assoc orbits-map a {:parent b, :children [], :depth (inc (:depth b))}) | |
9 | (update-in [b :children] conj a)) | |
10 | (-> (assoc orbits-map b {:parent nil, :children [], :depth 0}) | |
11 | (a-orbits-b [b a])))) | |
12 | ||
13 | (defn day06 [] | |
14 | (let [input (map #(str/split % #")") (get-list-from-file (input-file))) | |
15 | orbits-map (reduce a-orbits-b {} input)] | |
16 | (part1 (reduce + (map :depth orbits-map))) | |
17 | #_(part2))) |