src/2018/days/day-01.lisp @ dd27f6b2d778

2021/05 and 2021/06
author Steve Losh <steve@stevelosh.com>
date Mon, 06 Dec 2021 19:38:12 -0800
parents 182bdd87fd9e
children (none)
(advent:defpackage* :advent/2018/01)
(in-package :advent/2018/01)


(define-problem (2018 1) (data read-all) (522 73364)
  (values
    (summation data)
    (progn
      (setf (cdr (last data)) data) ; make data a circular list for easy looping
      (iterate
        (with seen = (make-hash-set :initial-contents '(0)))
        (for number :in data)
        (summing number :into frequency)
        (if (hset-contains-p seen frequency)
          (return frequency)
          (hset-insert! seen frequency))))))