aoc-2023

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

commit 32106b8de8932487f0a247105b1478057b5d425b
parent 382ca0313f5945be1a26648f7e6d9edc0793c70a
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date:   Sun, 10 Dec 2023 10:37:17 +0000

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

diff --git a/day10.scm b/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))