aoc-all

My solutions to all Advent of Code
git clone https://git.instinctive.eu/aoc-all.git
Log | Files | Refs | README | LICENSE

commit ffbe4a6f31432a9ec8256c7b13d14b3d2cefe33b
parent 2751d509133258a8b67747495679e2ee5cecae0b
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date:   Sun, 10 Dec 2023 10:37:17 +0000

Simplify day 10 solution
Diffstat:
M2023/day10.scm | 34++++++++++++++--------------------
1 file changed, 14 insertions(+), 20 deletions(-)

diff --git a/2023/day10.scm b/2023/day10.scm @@ -153,30 +153,24 @@ (read-cell data (cons x y)))) (define answer-2 - (let loop ((x 0) (y 0) (vert-before 0) (horiz-before 0) (acc 0)) + (let loop ((x 0) (y 0) (up-before 0) (down-before 0) (acc 0)) (cond ((>= y data-height) acc) ((>= x data-width) (loop 0 (add1 y) 0 0 acc)) ((>= (vec-ref-xy dist-from-start x y) 0) (case (tile-at x y) - ((#\|) (loop (add1 x) y (add1 vert-before) 0 acc)) - ((#\-) (assert (or (eqv? horiz-before #\F) - (eqv? horiz-before #\L))) - (loop (add1 x) y vert-before horiz-before acc)) - ((#\L) (loop (add1 x) y vert-before #\L acc)) - ((#\F) (loop (add1 x) y vert-before #\F acc)) - ((#\7) (loop (add1 x) y - (if (eqv? horiz-before #\L) - (add1 vert-before) - vert-before) - 0 acc)) - ((#\J) (loop (add1 x) y - (if (eqv? horiz-before #\F) - (add1 vert-before) - vert-before) - 0 acc)) + ((#\|) + (loop (add1 x) y (add1 up-before) (add1 down-before) acc)) + ((#\-) + (loop (add1 x) y up-before down-before acc)) + ((#\L #\J) + (loop (add1 x) y (add1 up-before) down-before acc)) + ((#\F #\7) + (loop (add1 x) y up-before (add1 down-before) acc)) (else (assert #f)))) - ((= 1 (remainder vert-before 2)) - (loop (add1 x) y vert-before 0 (add1 acc))) - (else (loop (add1 x) y vert-before 0 acc))))) + ((= 1 (remainder up-before 2) (remainder down-before 2)) + (loop (add1 x) y up-before down-before (add1 acc))) + ((= 0 (remainder up-before 2) (remainder down-before 2)) + (loop (add1 x) y up-before down-before acc)) + (else (assert #f))))) (write-line (conc "Second puzzle: " answer-2))