aboutsummaryrefslogtreecommitdiff
path: root/2021/day-12/day-12.rkt
diff options
context:
space:
mode:
Diffstat (limited to '2021/day-12/day-12.rkt')
-rw-r--r--2021/day-12/day-12.rkt28
1 files changed, 7 insertions, 21 deletions
diff --git a/2021/day-12/day-12.rkt b/2021/day-12/day-12.rkt
index 76a5aa8..18ed86f 100644
--- a/2021/day-12/day-12.rkt
+++ b/2021/day-12/day-12.rkt
@@ -11,23 +11,14 @@
(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)
- '()))
+ (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)))
+ (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 (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)]
@@ -38,15 +29,10 @@
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?)))
+ #:only-one-visit? (or (backtracking-disallowed? next-path path-list) visit-used-up?)))
(apply append))]))
-(~> (look-for-next-cave)
- length
- time)
+(~> (look-for-next-cave) length time)
;; part 2
-(~> (look-for-next-cave #:only-one-visit? #f)
- length
- time) \ No newline at end of file
+(~> (look-for-next-cave #:only-one-visit? #f) length time)