diff options
author | J.J <thechairman@thechairman.info> | 2023-11-30 17:10:00 -0500 |
---|---|---|
committer | J.J <thechairman@thechairman.info> | 2023-11-30 17:10:00 -0500 |
commit | 8ab65dc2da1742eb86ec636c50c7018385b68167 (patch) | |
tree | c4fd556aca9b867cfa1f2f174128c30857353884 /2021/day-12 | |
parent | fafbeaf9e3c09ba7a5bea7e47d5736001f8a5aa1 (diff) | |
download | gleam_aoc-8ab65dc2da1742eb86ec636c50c7018385b68167.tar.gz gleam_aoc-8ab65dc2da1742eb86ec636c50c7018385b68167.zip |
prep for 2023, renaming for consistency
Diffstat (limited to '2021/day-12')
-rw-r--r-- | 2021/day-12/day-12.rkt | 38 |
1 files changed, 0 insertions, 38 deletions
diff --git a/2021/day-12/day-12.rkt b/2021/day-12/day-12.rkt deleted file mode 100644 index 18ed86f..0000000 --- a/2021/day-12/day-12.rkt +++ /dev/null @@ -1,38 +0,0 @@ -#lang racket -(require "../../jj-aoc.rkt" - threading) - -(define path-pairs - (for/list ([l (in-lines (open-day 12 2021))]) - (match (string-split l "-") - [(list start end) (cons start end)]))) - -(define edges-hash (make-hash)) - -(for ([pair (in-list path-pairs)]) - (match-define (cons start end) pair) - (hash-update! edges-hash start (curry cons end) '()) - (hash-update! edges-hash end (curry cons start) '())) - -;; part 1 -(define (backtracking-disallowed? next prevs) - (and (equal? (string-downcase next) next) (member next prevs))) - -(define (look-for-next-cave [path-list '("start")] #: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))] - #: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) - #:only-one-visit? (or (backtracking-disallowed? next-path path-list) visit-used-up?))) - (apply append))])) - -(~> (look-for-next-cave) length time) - -;; part 2 -(~> (look-for-next-cave #:only-one-visit? #f) length time) |