From 8b4300ef235cc6bcb812fcf1226aadb01edecd7b Mon Sep 17 00:00:00 2001 From: Hunky Jimpjorps Date: Wed, 14 Dec 2022 10:47:07 -0500 Subject: day 12 tweaks --- 2022/day-12/day-12.rkt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to '2022/day-12/day-12.rkt') diff --git a/2022/day-12/day-12.rkt b/2022/day-12/day-12.rkt index 5e0c365..ed93453 100644 --- a/2022/day-12/day-12.rkt +++ b/2022/day-12/day-12.rkt @@ -1,7 +1,6 @@ #lang racket (require advent-of-code - fancy-app graph) (define raw-terrain (fetch-aoc-input (find-session) 2022 12 #:cache #true)) @@ -9,14 +8,15 @@ (define terrain-mesh (for*/hash ([(row x) (in-indexed (string-split raw-terrain))] [(col y) (in-indexed row)]) + (define p (cons x y)) (case col [(#\S) - (hash-set! special-points 'start (cons x y)) - (values (cons x y) 0)] + (hash-set! special-points 'start p) + (values p 0)] [(#\E) - (hash-set! special-points 'end (cons x y)) - (values (cons x y) 25)] - [else (values (cons x y) (- (char->integer col) (char->integer #\a)))]))) + (hash-set! special-points 'end p) + (values p 25)] + [else (values p (- (char->integer col) (char->integer #\a)))]))) (define (neighbors p) (match-define (cons x y) p) -- cgit v1.2.3 From 1765de8f51c0041c38423715308e4e6cec556564 Mon Sep 17 00:00:00 2001 From: Hunky Jimpjorps Date: Wed, 14 Dec 2022 10:47:10 -0500 Subject: day 12 tweaks --- 2022/day-12/day-12.rkt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to '2022/day-12/day-12.rkt') diff --git a/2022/day-12/day-12.rkt b/2022/day-12/day-12.rkt index ed93453..c3f01ac 100644 --- a/2022/day-12/day-12.rkt +++ b/2022/day-12/day-12.rkt @@ -23,16 +23,16 @@ (for*/list ([dx (in-list '(-1 0 1))] [dy (in-list '(-1 0 1))] #:when (= 1 (abs (+ dx dy))) - #:do [(define p (cons (+ x dx) (+ y dy)))] - #:when (hash-has-key? terrain-mesh p)) - p)) + #:do [(define p* (cons (+ x dx) (+ y dy)))] + #:when (hash-has-key? terrain-mesh p*)) + p*)) (define paths (directed-graph (for*/list ([p (in-list (hash-keys terrain-mesh))] - [neighbor (in-list (neighbors p))] - #:unless (> (sub1 (hash-ref terrain-mesh neighbor)) + [p* (in-list (neighbors p))] + #:unless (> (sub1 (hash-ref terrain-mesh p*)) (hash-ref terrain-mesh p))) - (list p neighbor)))) + (list p p*)))) ;; part 1 (time (match-define-values (distances _) (bfs paths (hash-ref special-points 'start))) -- cgit v1.2.3