diff options
| author | Syndamia <kamen@syndamia.com> | 2022-12-10 08:29:49 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2022-12-10 08:29:49 +0200 |
| commit | bd16b90f12e03e85a62232d705824430cf64fd23 (patch) | |
| tree | 9e5f68c2686e0d08f143f06e43034cfe5d0901e3 /2022/Day09/part-one.cl | |
| parent | 46b53fcf72f28d8a7bbbbd9d347232efa6c4de64 (diff) | |
| download | advent-of-code-bd16b90f12e03e85a62232d705824430cf64fd23.tar advent-of-code-bd16b90f12e03e85a62232d705824430cf64fd23.tar.gz advent-of-code-bd16b90f12e03e85a62232d705824430cf64fd23.zip | |
[2022/D09] Started work on yesterday's tasks
Diffstat (limited to '2022/Day09/part-one.cl')
| -rw-r--r-- | 2022/Day09/part-one.cl | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/2022/Day09/part-one.cl b/2022/Day09/part-one.cl new file mode 100644 index 0000000..9e44aa0 --- /dev/null +++ b/2022/Day09/part-one.cl @@ -0,0 +1,37 @@ +;;; https://gitlab.com/Syndamia/senzill +(require :senzill) +(use-package :senzill.math) +(use-package :senzill.collections) +(use-package :senzill.pair) +(use-package :senzill.io) + +(ask-for-stream (prog-input) + (let ((rhead '(0 . 0)) (rtail '(0 . 0)) (visited '((0 . 0))) (movec '())) + (flet ((p-longer-than-sqrt2 (c) + "If c is outside the 3x3 square" + (or (> (abs (car c)) 1) (> (abs (cdr c)) 1))) + + (movement-vec (c1 c2) + (cons (- (car c2) (car c1)) (- (cdr c2) (cdr c1)))) + + (dir-to-pair (direction) + (cond ((char= direction #\R) '( 1 . 0)) + ((char= direction #\L) '(-1 . 0)) + ((char= direction #\U) '( 0 . 1)) + ((char= direction #\D) '( 0 . -1))))) + + (doread-lines (inpt :read-line-options (prog-input NIL)) + (pair+= rhead (*pair (digit-char-p (char inpt 2)) + (dir-to-pair (char inpt 0)))) + + (setf movec (movement-vec rtail rhead)) + + (if (p-longer-than-sqrt2 movec) + (progn (setf movec (pair-round (dist-resize-by movec -1))) ; We dont want to move tail on the head, but behind it + (pair+= rtail movec) + + (loop for intermvec = movec then (pair-round (dist-resize-by intermvec -1)) + until (pair= intermvec '(0 . 0)) + if (not (member (pair- rtail intermvec) visited)) + do (push (pair- rtail intermvec) visited))))) + (print visited)))) |
