src/2017/days/day-03.lisp @ 35ad1f73c754

Add scratch.md to .hgignore
author Steve Losh <steve@stevelosh.com>
date Wed, 08 Dec 2021 21:47:32 -0800
parents 182bdd87fd9e
children (none)
(advent:defpackage* :advent/2017/03)
(in-package :advent/2017/03)


(defun neighbors (coord)
  (iterate (for (dx dy) :within-radius 1 :skip-origin t)
           (collect (+ coord (complex dx dy)))))

(define-problem (2017 3) (data read) (552 330785)
  (values
    (manhattan-distance #c(0 0) (advent/spiral:number-coordinates data))
    (iterate
      (with memory = (make-hash-table))
      (initially (setf (gethash #c(0 0) memory) 1))
      (for n :from 2)
      (for coord = (advent/spiral:number-coordinates n))
      (for value = (summation (neighbors coord) :key (rcurry #'gethash memory 0)))
      (finding value :such-that (> value data))
      (setf (gethash coord memory) value))))