commit d9c06ab77cf05742d3ee4533e07e6f2edfe34840 (patch) parent 87d7371ffa8a1555264aecc8d4a80d764f9479dc Author: Alex Karle <alex@alexkarle.com> Date: Sat, 10 Dec 2022 10:59:34 -0500 tmp Diffstat:
A | 2022/09/input | | | 2000 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | 2022/09/sample | | | 8 | ++++++++ |
A | 2022/09/sol.scm | | | 122 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
3 files changed, 2130 insertions(+), 0 deletions(-)
diff --git a/2022/09/input b/2022/09/input @@ -0,0 +1,2000 @@ +L 1 +D 2 +U 1 +L 1 +R 2 +L 2 +U 1 +D 2 +R 2 +L 2 +U 1 +D 2 +R 1 +D 2 +L 2 +D 1 +L 2 +R 1 +U 2 +R 2 +U 2 +L 2 +U 1 +L 2 +R 1 +D 1 +R 1 +L 1 +R 1 +L 1 +R 1 +U 1 +R 1 +L 1 +D 2 +L 2 +D 2 +L 1 +R 1 +D 1 +R 1 +D 2 +L 1 +D 2 +L 1 +R 2 +D 2 +R 2 +U 1 +R 1 +U 2 +R 1 +U 2 +R 1 +D 2 +L 1 +D 2 +U 1 +R 2 +D 2 +L 1 +U 2 +R 2 +L 2 +D 2 +L 2 +D 2 +R 1 +U 2 +L 2 +U 1 +R 1 +D 1 +L 1 +D 1 +U 1 +D 2 +L 1 +R 1 +D 1 +R 1 +L 2 +R 1 +L 1 +U 2 +D 2 +U 1 +L 1 +U 2 +R 1 +D 2 +U 1 +D 1 +L 1 +D 2 +U 2 +D 1 +U 2 +R 2 +L 2 +D 1 +R 2 +D 1 +L 2 +D 2 +L 2 +R 1 +L 1 +R 2 +L 2 +R 2 +U 1 +R 1 +U 3 +D 2 +U 3 +L 1 +R 1 +U 3 +D 1 +L 1 +R 3 +D 2 +L 3 +R 3 +D 2 +R 2 +U 3 +R 3 +U 3 +R 2 +U 3 +D 2 +L 3 +U 3 +R 1 +U 1 +R 3 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 9 +D 13 +R 3 +U 1 +D 12 +R 4 +D 11 +L 8 +D 8 +R 13 +D 16 +R 1 +D 10 +R 18 +U 6 +D 4 +U 17 +R 12 +L 14 +U 5 +L 15 +U 18 +R 4 +D 17 +L 4 +R 18 +U 18 +D 4 +L 1 +U 4 +L 2 +U 17 +R 16 +L 7 +U 10 +R 11 +U 9 +R 11 +L 16 +U 3 +R 3 +L 18 +U 8 +R 1 +U 1 +L 5 +U 5 +D 7 +L 1 +R 2 +U 16 +R 17 +D 4 +U 16 +L 12 +R 3 +L 16 +D 5 +U 5 +R 18 +L 7 +U 1 +L 7 +U 16 +R 14 +L 4 +R 13 +L 3 +U 4 +L 11 +U 3 +L 12 +U 16 +L 14 +U 3 +L 9 +R 18 +D 8 +L 15 +R 10 +D 2 +L 13 +D 11 +U 4 +L 13 +D 7 +L 12 +U 7 +D 17 +U 9 +D 5 +L 10 +R 2 +D 7 +L 14 +U 10 +D 17 +L 3 +R 17 +U 16 +D 13 +R 13 +U 14 +R 9 +L 3 +U 14 +L 7 +U 4 +D 1 +R 18 +U 11 +D 9 +U 8 +R 15 +L 5 +D 9 +L 2 +D 18 +U 12 +D 3 +U 14 +D 9 +U 13 +R 16 +U 8 +R 16 +U 4 +L 8 +D 14 +R 15 +D 6 +R 17 +U 6 +D 1 +L 2 +U 9 +D 15 +L 7 +D 3 +R 1 +L 1 +R 17 +D 12 +R 19 +U 4 +R 19 +L 2 +D 17 +U 11 +D 1 +L 9 +R 18 +L 7 +D 13 +U 6 +D 16 +L 6 +R 13 +U 12 +R 1 +L 2 +U 8 +L 16 +R 10 +D 15 +R 5 +L 1 +U 5 +R 18 +U 1 +R 4 +U 14 +R 3 +L 4 +U 13 +D 14 +L 10 +D 7 +U 3 +R 17 +L 19 +R 1 +D 12 +L 9 +U 19 +D 19 +L 5 +R 10 +L 14 +U 15 +D 19 +U 18 +D 14 +R 11 +U 8 +R 2 +U 16 +L 17 +D 6 +L 1 +D 10 +R 18 +U 5 +R 14 +U 10 +D 6 +L 17 +D 6 +U 7 +R 14 +L 1 +U 3 +D 3 +R 18 +D 1 +L 6 +D 18 +L 2 +R 10 +L 9 +R 10 +L 14 +R 15 +U 10 diff --git a/2022/09/sample b/2022/09/sample @@ -0,0 +1,8 @@ +R 4 +U 4 +L 3 +D 1 +R 4 +D 1 +L 5 +R 2 diff --git a/2022/09/sol.scm b/2022/09/sol.scm @@ -0,0 +1,122 @@ +#!/usr/local/bin/chicken-csi -ss +(import srfi-69 + (chicken string) + (chicken io)) + +(define (set-append set x) + (if (member x set) + set + (cons x set))) + +(define (range a b) + (let ((update (if (< a b) add1 sub1))) + (if (= a b) + '() + (cons a (range (update a) b))))) + +(define (parse-line l) + (let ((parts (string-split l))) + (list (string->symbol (car parts)) + (string->number (cadr parts))))) + +(define (move cmd pt) + (let ((dir (car cmd)) + (val (cadr cmd)) + (x (car pt)) + (y (cadr pt))) + (cond ((eq? dir 'U) + (list x (+ y val))) + ((eq? dir 'D) + (list x (- y val))) + ((eq? dir 'L) + (list (+ x val) y)) + ((eq? dir 'R) + (list (- x val) y)) + (else (error "Bad dir " dir))))) + + +(define (adjacent? a b) + (let ((xa (car a)) + (ya (cadr a)) + (xb (car b)) + (yb (cadr b))) + (and (<= (abs (- xa xb)) 1) + (<= (abs (- ya yb)) 1)))) + +(define (vert-walk yh yt x) + (map (lambda (y) (list x y)) (range yt yh))) + +(define (horiz-walk xh xt y) + (map (lambda (y) (list x y)) (range xt xh))) + + +;; Get direction of A with respect to B +(define (direction a b) + (let ((xa (car a)) + (ya (cadr a)) + (xb (car b)) + (yb (cadr b))) + (cond ((and (= xa xb) (= ya yb)) 'O) + ((and (= xa xb) (< ya yb)) 'S) + ((and (= xa xb) (> ya yb)) 'N) + ((and (< xa xb) (= ya yb)) 'W) + ((and (> xa xb) (= ya yb)) 'E) + ((and (< xa xb) (< ya yb)) 'SW) + ((and (< xa xb) (> ya yb)) 'NW) + ((and (> xa xb) (< ya yb)) 'SE) + ((and (> xa xb) (> ya yb)) 'NE) + (else (error "Unhandled dir case"))))) + +(define (follow h T seen) + (let ((xh (car h)) + (yh (cadr h)) + (xt (car T)) + (yt (cadr T)) + (dir (direction h T))) + ;; One dim should be off by 0 or 1 + ;; given that our last position was <= 1 away + (cond ((eq? dir 'N) + (vert-walk yh yt xh)) + ((eq? dir 'S) + (vert-walk yh yt xh)) + ((eq? dir 'E) + (horiz-walk xh xt yh)) + ((eq? dir 'W) + (horiz-walk xh xt yh)) + ((eq? dir 'NE)) ;; TODO: is this NE with x primary or y primary? matters + ((eq? dir 'NW)) + ((eq? dir 'SE)) + ((eq? dir 'SW)) + (else (error "Bad follow with dir " dir))) + +(define (do-cmd cmd H T seen) + ;; update head first + (let* ((h (move cmd H))) + (if (adjacent? h T) + (values h T seen) + (follow h T seen)))) + +(define (main args) + (let ((cmds (map parse-line (read-lines)))) + cmds)) + +;; For repl +(define slines '("R 4" + "U 4" + "L 3" + "D 1" + "R 4" + "D 1" + "L 5" + "R 2")) + +; (map parse-line slines) +; (move '(U 2) '(0 0)) +; (move '(D 2) '(0 0)) +; (move '(L 2) '(0 0)) +; (move '(R 2) '(0 0)) + +; (adjacent? '(0 0) '(1 4)) +; (adjacent? '(1 0) '(0 2)) +; (adjacent? '(0 0) '(0 1)) +; (adjacent? '(0 0) '(1 1))