diff options
author | HJ <thechairman@thechairman.info> | 2021-12-12 16:07:59 -0500 |
---|---|---|
committer | HJ <thechairman@thechairman.info> | 2021-12-12 16:07:59 -0500 |
commit | 3f32d009a1a18c9c4ab43e1af2136c9261d05de2 (patch) | |
tree | 782385c0d6e4aadeba4d8f1a6124b3c003b6dadc /2021/day-12/day-12.rkt | |
parent | 86501cf1748971a08e9a2f4e5b4413a273f33535 (diff) | |
download | gleam_aoc-3f32d009a1a18c9c4ab43e1af2136c9261d05de2.tar.gz gleam_aoc-3f32d009a1a18c9c4ab43e1af2136c9261d05de2.zip |
day 12 done
Diffstat (limited to '2021/day-12/day-12.rkt')
-rw-r--r-- | 2021/day-12/day-12.rkt | 19 |
1 files 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 |