]> localhost Git - adventofcode2019.git/commitdiff
Add untested day6pt1
authorJack Kinsey <kinsey_john@bah.com>
Fri, 6 Dec 2019 15:20:59 +0000 (10:20 -0500)
committerJack Kinsey <kinsey_john@bah.com>
Fri, 6 Dec 2019 15:20:59 +0000 (10:20 -0500)
src/adventofcode2019/core.clj
src/adventofcode2019/day06.clj [new file with mode: 0644]

index 2cb3822a572c908fe850effb3df68edf24b69f26..aeabe1d776cce2e4dcf65e4c7c574ce162ac77b9 100644 (file)
@@ -1,6 +1,6 @@
 (ns adventofcode2019.core
     [:require (adventofcode2019 day01 day02 day03
-                                day04 day05)])
+                                day04 day05 day06)])
 
 (defn -main 
   ([]
diff --git a/src/adventofcode2019/day06.clj b/src/adventofcode2019/day06.clj
new file mode 100644 (file)
index 0000000..1d67336
--- /dev/null
@@ -0,0 +1,17 @@
+(ns adventofcode2019.day06
+    [:require [adventofcode2019.lib :refer :all]
+              [clojure.string :as str]])
+
+;; FIXME: is the input guaranteed in-order?
+(defn a-orbits-b [orbits-map [b a]]
+  (if (contains? orbits-map b)
+    (-> (assoc orbits-map a {:parent b, :children [], :depth (inc (:depth b))})
+        (update-in [b :children] conj a))
+    (-> (assoc orbits-map b {:parent nil, :children [], :depth 0})
+        (a-orbits-b [b a]))))
+
+(defn day06 []
+  (let [input (map #(str/split % #")") (get-list-from-file (input-file)))
+        orbits-map (reduce a-orbits-b {} input)] 
+    (part1 (reduce + (map :depth orbits-map)))
+    #_(part2)))