src/2018/days/day-09.lisp @ 9ceb59a426ad
Remove unused macro
author |
Steve Losh <steve@stevelosh.com> |
date |
Sat, 07 Dec 2019 16:58:49 -0500 |
parents |
cd781337a694 |
children |
182bdd87fd9e |
(defpackage :advent/2018/09 #.cl-user::*advent-use*)
(in-package :advent/2018/09)
(named-readtables:in-readtable :interpol-syntax)
(defun parse-input (line)
(ppcre:register-groups-bind
((#'parse-integer players marbles))
(#?r"(\d+) players\D*(\d+) points" line)
(values players marbles)))
(defun play (players marbles)
(let ((circle (ring 0))
(elves (make-array players :initial-element 0)))
(iterate
(declare (iterate:declare-variables))
(for elf :first 0 :then (mod (1+ elf) players))
(for marble :from 1 :to marbles)
(if (dividesp marble 23)
(progn (incf (aref elves elf) marble)
(ring-movef circle -7)
(incf (aref elves elf) (ring-data circle))
(ring-cutf circle))
(progn (ring-movef circle 1)
(ring-insertf-after circle marble))))
(extremum elves '>)))
(define-problem (2018 9) (data alexandria:read-stream-content-into-string)
(398730 3349635509)
(multiple-value-bind (players marbles) (parse-input data)
#+sbcl (sb-ext:gc :full t)
(values (play players marbles)
(play players (* marbles 100)))))