bd509ececdf0
2021/02
author | Steve Losh <steve@stevelosh.com> |
---|---|
date | Thu, 02 Dec 2021 00:28:53 -0500 |
parents | 166414163a73 |
children | 08dd2b57f2c0 17eacdbd1e81 |
branches/tags | (none) |
files | data/2021/02.txt src/2020/days/day-11.lisp src/2021/days/day-02.lisp |
Changes
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/2021/02.txt Thu Dec 02 00:28:53 2021 -0500 @@ -0,0 +1,1000 @@ +forward 5 +down 8 +down 6 +down 7 +down 8 +forward 7 +down 3 +up 6 +forward 6 +down 2 +forward 5 +down 6 +up 3 +down 4 +forward 4 +down 6 +down 1 +up 5 +forward 5 +down 1 +down 7 +up 2 +down 7 +forward 1 +forward 6 +down 1 +up 1 +up 4 +forward 3 +forward 6 +forward 1 +forward 4 +up 3 +forward 1 +forward 4 +down 9 +forward 4 +forward 8 +up 8 +forward 5 +up 4 +up 3 +down 8 +forward 5 +down 4 +forward 1 +forward 7 +down 1 +forward 8 +down 4 +forward 2 +forward 7 +forward 9 +up 4 +down 3 +forward 7 +forward 6 +down 8 +forward 2 +forward 5 +forward 4 +down 6 +forward 6 +up 5 +down 3 +down 6 +down 5 +down 7 +down 8 +up 5 +down 5 +forward 5 +forward 4 +up 3 +down 7 +down 3 +forward 4 +down 2 +forward 4 +forward 3 +forward 4 +forward 9 +forward 6 +forward 8 +up 8 +down 8 +up 5 +down 4 +down 8 +up 7 +up 8 +down 6 +down 3 +forward 2 +forward 7 +up 1 +up 2 +forward 2 +down 7 +down 1 +up 9 +forward 6 +forward 4 +down 2 +up 6 +down 2 +down 1 +down 3 +up 6 +down 1 +down 8 +forward 7 +up 8 +forward 5 +forward 8 +down 8 +forward 6 +forward 8 +down 3 +down 4 +down 6 +up 2 +forward 6 +up 9 +forward 4 +forward 8 +up 4 +down 8 +forward 8 +down 8 +down 4 +down 5 +forward 7 +down 6 +down 6 +up 2 +up 1 +forward 7 +forward 8 +forward 4 +forward 9 +down 7 +forward 4 +up 5 +down 3 +up 4 +down 9 +down 2 +down 8 +forward 3 +forward 5 +forward 7 +forward 9 +forward 5 +forward 8 +forward 6 +forward 4 +forward 6 +forward 7 +forward 2 +down 1 +down 8 +down 4 +down 5 +down 6 +up 3 +up 2 +forward 4 +down 4 +forward 7 +up 6 +up 9 +down 1 +down 3 +down 1 +up 3 +up 1 +down 2 +up 5 +forward 1 +down 7 +forward 9 +down 4 +up 4 +down 6 +down 3 +forward 4 +up 6 +up 4 +forward 1 +up 7 +down 1 +down 7 +down 7 +forward 9 +down 3 +down 3 +forward 6 +down 2 +forward 7 +up 4 +up 8 +down 8 +forward 7 +forward 6 +down 7 +forward 5 +up 6 +up 6 +down 9 +up 6 +up 2 +forward 9 +forward 1 +up 5 +up 3 +down 9 +up 8 +down 7 +up 7 +forward 5 +down 7 +down 4 +forward 2 +forward 3 +forward 5 +down 1 +up 6 +down 6 +up 6 +down 8 +down 3 +down 4 +forward 9 +down 3 +forward 3 +up 1 +down 2 +forward 8 +down 7 +up 9 +forward 1 +down 3 +forward 1 +forward 8 +down 3 +forward 8 +forward 6 +down 1 +down 9 +forward 2 +down 1 +down 6 +up 1 +up 7 +down 9 +forward 6 +forward 5 +forward 2 +up 6 +down 6 +forward 6 +up 3 +down 7 +down 8 +forward 5 +down 7 +forward 8 +down 8 +forward 4 +down 6 +forward 4 +down 7 +up 5 +down 5 +down 5 +down 4 +down 3 +forward 8 +forward 1 +down 8 +down 2 +forward 3 +forward 7 +forward 3 +down 5 +down 6 +down 8 +down 6 +forward 9 +forward 4 +forward 8 +down 5 +down 7 +forward 4 +up 5 +down 8 +up 6 +up 7 +down 6 +down 8 +forward 3 +up 6 +forward 7 +down 4 +up 1 +up 8 +forward 3 +down 6 +down 1 +forward 7 +down 1 +down 9 +forward 6 +down 4 +forward 3 +forward 1 +down 5 +down 9 +down 9 +down 5 +down 8 +down 7 +forward 1 +forward 5 +down 2 +forward 2 +forward 1 +down 8 +forward 6 +down 3 +forward 4 +up 2 +up 8 +forward 7 +forward 4 +down 8 +up 6 +forward 3 +up 1 +up 2 +forward 5 +forward 9 +down 5 +forward 2 +forward 5 +up 6 +down 1 +down 1 +down 6 +forward 6 +down 7 +forward 5 +forward 8 +down 7 +down 5 +forward 9 +forward 1 +up 6 +down 7 +forward 1 +forward 4 +down 5 +down 6 +up 3 +up 8 +up 5 +down 8 +down 8 +down 6 +down 2 +down 3 +down 9 +forward 8 +forward 7 +forward 7 +up 5 +down 5 +forward 9 +up 8 +up 5 +forward 1 +down 9 +down 9 +forward 9 +forward 4 +forward 6 +up 9 +up 5 +up 3 +down 9 +up 7 +up 1 +down 3 +down 9 +down 7 +forward 6 +down 7 +forward 7 +forward 8 +down 2 +forward 5 +up 1 +down 6 +up 9 +forward 5 +up 9 +down 2 +down 3 +forward 5 +down 9 +forward 9 +forward 2 +forward 8 +down 1 +forward 8 +up 1 +forward 3 +up 1 +down 1 +forward 9 +down 2 +forward 2 +up 1 +up 8 +down 2 +down 7 +down 5 +up 2 +up 6 +down 9 +down 7 +down 7 +up 6 +up 8 +down 7 +forward 5 +down 4 +down 5 +up 8 +up 6 +down 6 +forward 6 +up 6 +down 1 +down 1 +down 1 +forward 1 +down 8 +down 4 +down 5 +down 2 +down 5 +up 8 +up 8 +down 3 +down 6 +down 1 +forward 6 +forward 5 +forward 1 +down 3 +down 4 +up 9 +down 3 +up 8 +forward 5 +down 5 +forward 2 +down 8 +down 2 +up 1 +forward 7 +up 8 +forward 7 +down 3 +down 1 +down 3 +forward 4 +down 5 +down 8 +forward 8 +forward 3 +forward 7 +down 7 +forward 4 +down 1 +forward 3 +up 2 +down 7 +down 1 +forward 4 +forward 7 +down 3 +down 1 +forward 4 +down 3 +forward 2 +up 9 +down 5 +down 9 +forward 5 +up 5 +down 3 +up 6 +up 8 +down 7 +down 3 +down 9 +forward 6 +forward 8 +forward 3 +down 6 +up 8 +forward 8 +forward 9 +down 4 +down 1 +forward 2 +down 2 +up 2 +down 5 +down 1 +down 3 +forward 4 +down 3 +up 8 +up 6 +up 5 +down 4 +forward 3 +up 6 +forward 6 +forward 2 +down 8 +down 5 +forward 3 +up 1 +forward 5 +forward 9 +forward 5 +down 5 +forward 3 +forward 6 +forward 5 +forward 3 +down 1 +down 1 +down 1 +down 9 +forward 8 +forward 2 +forward 4 +forward 8 +down 1 +up 8 +down 1 +down 6 +down 5 +up 8 +down 4 +forward 8 +forward 6 +down 6 +forward 2 +forward 7 +forward 2 +up 7 +forward 4 +up 1 +up 8 +down 3 +down 2 +down 3 +up 7 +down 9 +up 5 +down 1 +down 3 +up 5 +down 6 +up 9 +down 4 +down 7 +down 6 +down 4 +forward 5 +forward 6 +down 8 +forward 3 +forward 8 +up 5 +up 6 +up 8 +forward 8 +forward 1 +down 6 +forward 3 +forward 3 +forward 6 +down 3 +down 2 +forward 5 +down 5 +forward 6 +down 3 +down 9 +down 8 +down 6 +down 6 +forward 1 +up 5 +down 9 +forward 3 +forward 3 +down 2 +forward 8 +forward 3 +forward 2 +forward 5 +down 4 +down 1 +up 2 +down 1 +down 1 +forward 5 +down 7 +up 7 +down 9 +down 8 +down 6 +forward 3 +forward 5 +down 3 +down 6 +up 3 +up 2 +up 8 +down 3 +up 3 +down 6 +forward 7 +forward 4 +up 5 +forward 1 +up 3 +forward 8 +down 2 +down 5 +down 2 +forward 4 +forward 4 +down 4 +up 8 +down 1 +up 2 +forward 2 +forward 9 +forward 4 +down 3 +down 7 +forward 1 +down 2 +forward 8 +down 8 +forward 3 +down 7 +forward 9 +forward 6 +up 1 +forward 3 +up 2 +up 3 +forward 6 +down 8 +up 9 +down 2 +down 9 +down 6 +down 4 +forward 5 +forward 3 +up 7 +forward 7 +up 7 +up 6 +down 7 +down 2 +up 7 +down 5 +up 9 +forward 3 +up 6 +up 6 +up 6 +up 1 +forward 5 +forward 5 +down 8 +forward 6 +forward 7 +down 3 +down 4 +down 2 +down 4 +down 1 +forward 7 +down 7 +down 5 +forward 8 +up 6 +up 8 +forward 8 +forward 2 +forward 4 +down 6 +down 4 +down 2 +down 3 +forward 8 +forward 6 +down 3 +forward 7 +forward 4 +up 8 +down 9 +forward 5 +up 5 +up 5 +up 7 +forward 3 +up 1 +down 2 +forward 5 +forward 5 +up 1 +forward 4 +down 6 +up 5 +up 3 +forward 9 +down 9 +down 6 +down 1 +down 2 +down 4 +down 7 +forward 3 +up 5 +forward 2 +down 3 +forward 7 +up 8 +up 3 +forward 6 +up 7 +up 1 +up 2 +down 5 +forward 5 +down 3 +down 5 +down 6 +up 1 +down 2 +up 1 +forward 3 +down 3 +down 4 +down 6 +down 1 +down 3 +forward 9 +forward 1 +down 1 +up 3 +forward 4 +forward 7 +forward 4 +down 2 +forward 6 +forward 2 +forward 7 +down 9 +forward 8 +forward 3 +up 8 +down 9 +up 8 +forward 5 +forward 9 +down 4 +forward 1 +up 9 +forward 2 +down 6 +up 3 +forward 1 +forward 3 +forward 8 +down 7 +down 3 +down 5 +down 2 +down 2 +forward 4 +forward 1 +down 2 +up 8 +down 2 +forward 3 +down 2 +down 6 +down 1 +up 1 +down 7 +down 3 +forward 3 +forward 1 +forward 9 +down 9 +down 2 +up 1 +forward 9 +up 2 +down 2 +forward 3 +down 4 +forward 9 +forward 5 +up 5 +forward 2 +up 3 +forward 8 +down 3 +forward 5 +forward 5 +down 8 +up 9 +forward 7 +up 2 +up 2 +up 1 +up 7 +down 8 +forward 9 +forward 9 +up 6 +down 5 +forward 7 +down 9 +down 8 +down 5 +down 3 +down 2 +forward 6 +down 7 +forward 3 +up 5 +forward 1 +up 7 +forward 3 +down 5 +down 9 +down 8 +forward 2 +up 4 +forward 7 +forward 5 +forward 8 +forward 7 +up 7 +forward 4 +up 7 +down 9 +forward 1 +forward 3 +down 3 +forward 4 +down 3 +forward 3 +down 5 +down 1 +forward 6 +down 4 +down 3 +down 2 +up 1 +down 1 +down 6 +down 6 +forward 9 +down 5 +forward 1 +up 4 +forward 7 +down 8 +forward 1 +forward 9 +forward 7 +down 1 +down 3 +up 2 +down 5 +up 6 +forward 2 +up 2 +down 7 +down 9 +forward 3 +up 5 +up 7 +down 4 +forward 6 +down 8 +forward 7 +up 1 +up 4 +forward 4 +down 9 +forward 9 +forward 9 +down 3 +forward 5 +forward 1 +down 3 +down 8 +forward 7 +down 4 +forward 3 +down 3 +forward 8 +forward 2 +forward 6 +up 9 +forward 2 +down 9 +forward 2 +down 1 +forward 9 +up 1 +up 4 +up 1 +down 1 +forward 4 +up 9 +up 8 +down 1 +down 3 +down 2 +forward 9 +down 7 +down 4 +forward 2 +up 9 +down 7 +down 1 +down 9 +forward 2 +down 2 +forward 9 +down 5 +up 1 +down 3 +up 6 +down 4 +forward 8 +down 2 +down 2 +down 9 +forward 9 +forward 2 +down 1 +forward 6 +down 2 +up 4 +down 8 +up 4 +down 6 +down 2 +forward 7 +down 3 +up 3 +forward 1 +up 4 +forward 5 +down 7 +down 8 +forward 7 +forward 3 +down 5 +up 6 +down 7 +down 1 +up 7 +down 1 +forward 6 +forward 3 +forward 3 +forward 7
--- a/src/2020/days/day-11.lisp Wed Dec 01 21:48:27 2021 -0500 +++ b/src/2020/days/day-11.lisp Thu Dec 02 00:28:53 2021 -0500 @@ -5,13 +5,9 @@ (when (array-in-bounds-p seats row col) (aref seats row col))) -(defun count-neighbors (seats row col &aux (result 0)) - (do-irange ((dr -1 1) - (dc -1 1)) - (unless (= 0 dr dc) - (when (eql #\# (sref seats (+ row dr) (+ col dc))) - (incf result)))) - result) +(defun count-neighbors (seats row col) + (iterate (for (r c) :within-radius 1 :origin (row col) :skip-origin t) + (counting (eql #\# (sref seats r c))))) (defun count-visible (seats row col &aux (result 0)) (do-irange ((dr -1 1)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/2021/days/day-02.lisp Thu Dec 02 00:28:53 2021 -0500 @@ -0,0 +1,37 @@ +(advent:defpackage* :advent/2021/02) +(in-package :advent/2021/02) + +(defun parse (stream) + (iterate (for line :in-stream stream :using #'read-line) + (ppcre:register-groups-bind ((#'ensure-keyword command) (#'parse-integer n)) + ("(\\w+) (\\d+)" line) + (collect (cons command n))))) + +(defun horiz (pos) (realpart pos)) +(defun depth (pos) (imagpart pos)) + +(defun part1 (course) + (iterate (for (cmd . n) :in course) + (summing (ecase cmd + (:forward (complex n 0)) + (:down (complex 0 n)) + (:up (complex 0 (- n))))))) + +(defun part2 (course) + (iterate (with pos = 0) + (with aim = 0) + (for (cmd . n) :in course) + (ecase cmd + (:forward (incf pos (complex n (* n aim)))) + (:down (incf aim n)) + (:up (decf aim n))) + (returning pos))) + +(define-problem (2021 2) (data) (1660158 1604592846) + (let* ((course (parse data)) + (p1 (part1 course)) + (p2 (part2 course))) + (values (* (horiz p1) (depth p1)) + (* (horiz p2) (depth p2))))) + +#; Scratch --------------------------------------------------------------------