From 3f32d009a1a18c9c4ab43e1af2136c9261d05de2 Mon Sep 17 00:00:00 2001 From: HJ Date: Sun, 12 Dec 2021 16:07:59 -0500 Subject: day 12 done --- 2021/day-12/day-12.rkt | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/2021/day-12/day-12.rkt b/2021/day-12/day-12.rkt index 0b1f414..8995fea 100644 --- a/2021/day-12/day-12.rkt +++ b/2021/day-12/day-12.rkt @@ -21,25 +21,25 @@ '())) ;; part 1 -(define (backtracking-allowed? next prevs) +(define (backtracking-disallowed? next prevs) (and (equal? (string-downcase next) next) (member next prevs))) (define (look-for-next-cave [path-list '("start")] - #:two-visits? [visit-used-up? #t]) + #:only-one-visit? [visit-used-up? #t]) (define current-cave (car path-list)) (cond [(equal? current-cave "end") (list path-list)] [else (~>> (for/list ([next-path (in-list (hash-ref edges-hash current-cave null))] - #:unless (equal? next-path "start") - #:when (not (and (backtracking-allowed? next-path path-list) - visit-used-up?))) + #:when (and (not (equal? next-path "start")) + (not (and (backtracking-disallowed? next-path path-list) + visit-used-up?)))) (look-for-next-cave (cons next-path path-list) - #:two-visits? (or (backtracking-allowed? next-path path-list) - visit-used-up?))) + #:only-one-visit? (or (backtracking-disallowed? next-path path-list) + visit-used-up?))) (apply append))])) (~> (look-for-next-cave) @@ -47,6 +47,5 @@ time) ;; part 2 -(~> (look-for-next-cave #:two-visits? #f) - length - time) \ No newline at end of file +(~> (look-for-next-cave #:only-one-visit? #f) + length) \ No newline at end of file -- cgit v1.2.3