From c0bc8aca2b8f66f69477d719c1a040c4e56cecc2 Mon Sep 17 00:00:00 2001 From: Jack Kinsey Date: Fri, 6 Dec 2019 10:20:59 -0500 Subject: [PATCH] Add untested day6pt1 --- src/adventofcode2019/core.clj | 2 +- src/adventofcode2019/day06.clj | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/adventofcode2019/day06.clj diff --git a/src/adventofcode2019/core.clj b/src/adventofcode2019/core.clj index 2cb3822..aeabe1d 100644 --- a/src/adventofcode2019/core.clj +++ b/src/adventofcode2019/core.clj @@ -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 index 0000000..1d67336 --- /dev/null +++ b/src/adventofcode2019/day06.clj @@ -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))) -- 2.38.5