src/2019/days/day-06.lisp @ 6614131d7b10

2021/11 2021/12 2021/13
author Steve Losh <steve@stevelosh.com>
date Mon, 13 Dec 2021 12:42:30 -0500
parents 182bdd87fd9e
children (none)
(advent:defpackage* :advent/2019/06)
(in-package :advent/2019/06)

(define-problem (2019 6) (data read-lines) (301100 547)
  (let ((graph (digraph:make-digraph :test #'equal)))
    (iterate
      (for line :in data)
      (for (mass orbiter) = (str:split ")" line))
      (digraph:insert-vertex graph mass)
      (digraph:insert-vertex graph orbiter)
      (digraph:insert-edge graph mass orbiter))
    (values
      (recursively ((n 0)
                    (node "COM"))
        (summation (digraph:successors graph node)
                   :initial-value n
                   :key (curry #'recur (1+ n))))
      (- (length
           (astar :start "YOU"
                  :neighbors (curry #'digraph:neighbors graph)
                  :goalp (curry #'equal "SAN")
                  :cost (constantly 1)
                  :heuristic (constantly 0)
                  :test #'equal))
         3))))