From: Jack Kinsey Date: Fri, 6 Dec 2019 15:20:59 +0000 (-0500) Subject: Add untested day6pt1 X-Git-Url: http://git.jkinsey.net/?a=commitdiff_plain;h=c0bc8aca2b8f66f69477d719c1a040c4e56cecc2;p=adventofcode2019.git Add untested day6pt1 --- 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)))