src/2016/days/day-01.lisp @ 2848a4548adf

2023/01 and 2022/01

Also start porting my test data to the new account, since Twitter imploded and
apparently it's impossible for a website to store a goddamn username and
password in The Year of Our Lord 2023 so everyone just outsources auth all
the time, ugh.
author Steve Losh <steve@stevelosh.com>
date Fri, 01 Dec 2023 11:05:43 -0500
parents 182bdd87fd9e
children (none)
(advent:defpackage* :advent/2016/01)
(in-package :advent/2016/01)


(defun turn (direction heading)
  (* heading (ecase direction
               (#\L #c(0 1))
               (#\R #c(0 -1)))))

(define-problem (2016 1) (data read-line) (146 131)
  (iterate
    (with pos = #c(0 0))
    (with seen = (make-hash-set :initial-contents (list #c(0 0))))
    (for ((#'first-character direction) (#'parse-integer distance))
         :matching "([LR])(\\d+)" :against data)
    (for heading :seed #c(0 1) :then (turn direction heading))
    (do-repeat distance
      (incf pos heading)
      (finding-first pos :such-that (hset-contains-p seen pos) :into part2)
      (hset-insert! seen pos))
    (returning (manhattan-distance pos)
               (manhattan-distance part2))))


#; Scratch --------------------------------------------------------------------