aboutsummaryrefslogtreecommitdiff
path: root/2021
diff options
context:
space:
mode:
authorHJ <thechairman@thechairman.info>2021-12-25 14:57:56 -0500
committerHJ <thechairman@thechairman.info>2021-12-25 14:57:56 -0500
commit5c650dd144bb15bf1648045471aac01b76d47b86 (patch)
tree5b8a87d15130bbfe5a3bcafe6ea692b318623263 /2021
parent2c400df353f83c46b61b723c97b5f92b24a45353 (diff)
downloadgleam_aoc-5c650dd144bb15bf1648045471aac01b76d47b86.tar.gz
gleam_aoc-5c650dd144bb15bf1648045471aac01b76d47b86.zip
day 25 complete
Diffstat (limited to '2021')
-rw-r--r--2021/day-25/day-25.rkt45
1 files changed, 45 insertions, 0 deletions
diff --git a/2021/day-25/day-25.rkt b/2021/day-25/day-25.rkt
new file mode 100644
index 0000000..ba18b45
--- /dev/null
+++ b/2021/day-25/day-25.rkt
@@ -0,0 +1,45 @@
+#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 \ No newline at end of file