diff options
author | H.J <thechairman@thechairman.info> | 2024-10-09 11:36:55 -0400 |
---|---|---|
committer | H.J <thechairman@thechairman.info> | 2024-10-09 11:36:55 -0400 |
commit | 8777ff071f7bb37631baa7b6717ad29961e50911 (patch) | |
tree | 6d59c4ed58e454b960339c3d1151f0a879e8d7cb /racket/aoc2021/day-25/day-25.rkt | |
parent | 6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff) | |
download | gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip |
sorting by language
Diffstat (limited to 'racket/aoc2021/day-25/day-25.rkt')
-rw-r--r-- | racket/aoc2021/day-25/day-25.rkt | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/racket/aoc2021/day-25/day-25.rkt b/racket/aoc2021/day-25/day-25.rkt new file mode 100644 index 0000000..7a3a5ca --- /dev/null +++ b/racket/aoc2021/day-25/day-25.rkt @@ -0,0 +1,35 @@ +#lang racket +(require "../../jj-aoc.rkt" + threading) + +(define sea-floor + (for*/hash ([(row i) (in-indexed (in-lines (open-day 25 2021)))] [(c j) (in-indexed row)]) + (values (list i j) c))) + +(define-values (max-i max-j) + (~> sea-floor hash-keys (argmax (λ (coord) (apply + coord)) _) (apply values _))) + +(define (cucumber-movement h c delta-i delta-j) + (define new-hash (hash-copy h)) + (for* ([(coord x) (in-hash h)] #:when (eq? x c)) + (match-define (list i j) coord) + (define neighbor (list (+ delta-i i) (+ delta-j j))) + (define neighbor-or-wrap + (if (hash-has-key? h neighbor) neighbor (list (if (= delta-i 0) i 0) (if (= delta-j 0) j 0)))) + (when (eq? #\. (hash-ref h neighbor-or-wrap)) + (hash-set*! new-hash coord #\. neighbor-or-wrap c))) + new-hash) + +(define (eastwards-movement h) + (cucumber-movement h #\> 0 1)) + +(define (southwards-movement h) + (cucumber-movement h #\v 1 0)) + +;; part 1 +(for/fold ([f sea-floor] [step 0] #:result (add1 step)) ([i (in-naturals 1)]) + (define f* (~> f eastwards-movement southwards-movement)) + #:break (equal? f* f) + (values f* i)) + +;; no part 2 -- merry Christmas |