# HG changeset patch # User Steve Losh # Date 1575694253 18000 # Node ID ebb7ecd4844ff7b606f16ea4975fef5e87a6a8aa # Parent 4febe2904f456ce7cb1915b7cee39f6b55a535a8 2016/02 diff -r 4febe2904f45 -r ebb7ecd4844f data/2016/02.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/2016/02.txt Fri Dec 06 23:50:53 2019 -0500 @@ -0,0 +1,5 @@ +DLRURUDLULRDRUDDRLUUUDLDLDLRLRRDRRRLLLLLDDRRRDRRDRRRLRRURLRDUULRLRRDDLULRLLDUDLULURRLRLDUDLURURLDRDDULDRDRDLDLLULULLDDLRRUDULLUULRRLLLURDRLDDLDDLDRLRRLLRURRUURRRRLUDLRDDDDRDULRLLDDUURDUDRLUDULLUDLUDURRDRDUUUUDDUDLLLRLUULRUURDLRLLRRLRLLDLLRLLRRRURLRRLURRLDLLLUUDURUDDLLUURRDRDRRDLLDDLLRDRDRRLURLDLDRDLURLDULDRURRRUDLLULDUDRURULDUDLULULRRRUDLUURRDURRURRLRRLLRDDUUUUUDUULDRLDLLRRUDRRDULLLDUDDUDUURLRDLULUUDLDRDUUUDDDUDLDURRULUULUUULDRUDDLLLDLULLRLRLUDULLDLLRLDLDDDUUDURDDDLURDRRDDLDRLLRLRR +RLDUDURDRLLLLDDRRRURLLLRUUDDLRDRDDDUDLLUDDLRDURLDRDLLDRULDDRLDDDRLDRDDDRLLULDURRRLULDRLRDRDURURRDUDRURLDRLURDRLUULLULLDLUDUDRDRDDLDDDDRDURDLUDRDRURUDDLLLRLDDRURLLUDULULDDLLLDLUDLDULUUDLRLURLDRLURURRDUUDLRDDDDDRLDULUDLDDURDLURLUURDLURLDRURRLDLLRRUDRUULLRLDUUDURRLDURRLRUULDDLDLDUUDDRLDLLRRRUURLLUURURRURRLLLUDLDRRDLUULULUDDULLUDRLDDRURDRDUDULUDRLRRRUULLDRDRLULLLDURURURLURDLRRLLLDRLDUDLLLLDUUURULDDLDLLRRUDDDURULRLLUDLRDLUUDDRDDLLLRLUURLDLRUURDURDDDLLLLLULRRRURRDLUDLUURRDRLRUDUUUURRURLRDRRLRDRDULLDRDRLDURDDUURLRUDDDDDLRLLRUDDDDDURURRLDRRUUUDLURUUDRRDLLULDRRLRRRLUUUD +RDRURLLUUDURURDUUULLRDRLRRLRUDDUDRURLLDLUUDLRLLDDURRURLUDUDDURLURLRRURLLURRUDRUDLDRLLURLRUUURRUDDDURRRLULLLLURDLRLLDDRLDRLLRRDLURDLRDLDUDRUULLDUUUDLURRLLRUDDDUUURLURUUDRLRULUURLLRLUDDLLDURULLLDURDLULDLDDUDULUDDULLRDRURDRRLLDLDDDDRUDLDRRLLLRLLLRRULDLRLRLRLLDLRDRDLLUDRDRULDUURRDDDRLLRLDLDRDUDRULUDRDLDLDDLLRULURLLURDLRRDUDLULLDLULLUDRRDDRLRURRLDUDLRRUUDLDRLRLDRLRRDURRDRRDDULURUUDDUUULRLDRLLDURRDLUULLUDRDDDLRUDLRULLDDDLURLURLRDRLLURRRUDLRRLURDUUDRLRUUDUULLRUUUDUUDDUURULDLDLURLRURLRUDLULLULRULDRDRLLLRRDLU +RRRRDRLUUULLLRLDDLULRUUURRDRDRURRUURUDUULRULULRDRLRRLURDRRRULUUULRRUUULULRDDLLUURRLLDUDRLRRLDDLDLLDURLLUDLDDRRURLDLULRDUULDRLRDLLDLRULLRULLUDUDUDDUULDLUUDDLUDDUULLLLLURRDRULURDUUUDULRUDLLRUUULLUULLLRUUDDRRLRDUDDRULRDLDLLLLRLDDRRRULULLLDLRLURRDULRDRDUDDRLRLDRRDLRRRLLDLLDULLUDDUDDRULLLUDDRLLRRRLDRRURUUURRDLDLURRDLURULULRDUURLLULDULDUDLLULDDUURRRLDURDLUDURLDDRDUDDLLUULDRRLDLLUDRDURLLDRLDDUDURDLUUUUURRUULULLURLDUUULLRURLLLUURDULLUULDRULLUULRDRUULLRUDLDDLRLURRUUDRLRRRULRUUULRULRRLDLUDRRLL +ULRLDLLURDRRUULRDUDDURDDDLRRRURLDRUDDLUDDDLLLRDLRLLRRUUDRRDRUULLLULULUUDRRRDRDRUUUUULRURUULULLULDULURRLURUDRDRUDRURURUDLDURUDUDDDRLRLLLLURULUDLRLDDLRUDDUUDURUULRLLLDDLLLLRRRDDLRLUDDUULRRLLRDUDLLDLRRUUULRLRDLRDUDLLLDLRULDRURDLLULLLRRRURDLLUURUDDURLDUUDLLDDRUUDULDRDRDRDDUDURLRRRRUDURLRRUDUDUURDRDULRLRLLRLUDLURUDRUDLULLULRLLULRUDDURUURDLRUULDURDRRRLLLLLUUUULUULDLDULLRURLUDLDRLRLRLRDLDRUDULDDRRDURDDULRULDRLRULDRLDLLUDLDRLRLRUDRDDR diff -r 4febe2904f45 -r ebb7ecd4844f src/2016/days/day-02.lisp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/2016/days/day-02.lisp Fri Dec 06 23:50:53 2019 -0500 @@ -0,0 +1,62 @@ +(defpackage :advent/2016/02 #.cl-user::*advent-use*) +(in-package :advent/2016/02) + +(defparameter *pad* 1) + +(defparameter *pads* + #(nil + ((#c(-1 1) . #\1) (#c(0 1) . #\2) (#c(1 1) . #\3) + (#c(-1 0) . #\4) (#c(0 0) . #\5) (#c(1 0) . #\6) + (#c(-1 -1) . #\7) (#c(0 -1) . #\8) (#c(1 -1) . #\9)) + + ( (#c(0 2) . #\1) + (#c(-1 1) . #\2) (#c(0 1) . #\3) (#c(1 1) . #\4) + (#c(-2 0) . #\5) (#c(-1 0) . #\6) (#c(0 0) . #\7) (#c(1 0) . #\8) (#c(2 0) . #\9) + (#c(-1 -1) . #\A) (#c(0 -1) . #\B) (#c(1 -1) . #\C) + (#c(0 -2) . #\D)))) + +(defun delta (direction) + (ecase direction + (#\U #c( 0 1)) + (#\D #c( 0 -1)) + (#\L #c(-1 0)) + (#\R #c( 1 0)))) + +(defun validp (position) + (member position (aref *pads* *pad*) :key #'car)) + +(defun move (position direction) + (let ((next (+ position (delta direction)))) + (if (validp next) + next + position))) + +(defun button (position) + (cdr (assoc position (aref *pads* *pad*)))) + +(defun find-button (directions start) + (iterate + (for dir :in-string directions) + (for pos :seed start :then (move pos dir)) + (returning (button pos) pos))) + +(defun find-code (lines) + (iterate + (with pos = 0) + (for directions :in lines) + (for (values button next) = (find-button directions pos)) + (setf pos next) + (collect button :result-type 'string))) + +(define-problem (2016 2) (data read-lines) ("95549" "D87AD") + (values (let ((*pad* 1)) (find-code data)) + (let ((*pad* 2)) (find-code data)))) + +#; Scratch -------------------------------------------------------------------- + +(run '("ULL" + "RRDDD" + "LURDL" + "UUUUD")) + +(run '("LURDL")) diff -r 4febe2904f45 -r ebb7ecd4844f src/2018/days/day-10.lisp --- a/src/2018/days/day-10.lisp Fri Dec 06 23:23:26 2019 -0500 +++ b/src/2018/days/day-10.lisp Fri Dec 06 23:50:53 2019 -0500 @@ -1,5 +1,5 @@ (defpackage :advent/2018/10 #.cl-user::*advent-use* - (:shadow :x)) + (:shadow :x :y)) (in-package :advent/2018/10) (defun parse-line (line)