aboutsummaryrefslogtreecommitdiff
path: root/aoc2021/day-15/day-15-list-nodes.rkt
diff options
context:
space:
mode:
authorH.J <thechairman@thechairman.info>2024-10-09 11:36:55 -0400
committerH.J <thechairman@thechairman.info>2024-10-09 11:36:55 -0400
commit8777ff071f7bb37631baa7b6717ad29961e50911 (patch)
tree6d59c4ed58e454b960339c3d1151f0a879e8d7cb /aoc2021/day-15/day-15-list-nodes.rkt
parent6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff)
downloadgleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz
gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip
sorting by language
Diffstat (limited to 'aoc2021/day-15/day-15-list-nodes.rkt')
-rw-r--r--aoc2021/day-15/day-15-list-nodes.rkt67
1 files changed, 0 insertions, 67 deletions
diff --git a/aoc2021/day-15/day-15-list-nodes.rkt b/aoc2021/day-15/day-15-list-nodes.rkt
deleted file mode 100644
index 38c558a..0000000
--- a/aoc2021/day-15/day-15-list-nodes.rkt
+++ /dev/null
@@ -1,67 +0,0 @@
-#lang racket
-(require "../../jj-aoc.rkt"
- threading
- graph)
-
-(define data
- (for/fold ([cells (hash)])
- ([row (in-lines (open-day 15 2021))]
- [x (in-naturals)])
- (for/fold ([cells cells])
- ([n (in-string row)]
- [y (in-naturals)])
- (hash-set cells
- `(,x ,y)
- (~> n string string->number)))))
-
-(define x-max (~>> data hash-keys (map first) (apply max)))
-(define y-max (~>> data hash-keys (map second) (apply max)))
-
-(define (neighbors pt d)
- (match-define (list x y) pt)
- (~>> (list (list (add1 x) y)
- (list (sub1 x) y)
- (list x (add1 y))
- (list x (sub1 y)))
- (filter (curry hash-has-key? d))))
-
-(define (grid-graph d)
- (weighted-graph/directed
- (for*/list ([coord (in-list (hash-keys d))]
- [neighbor (in-list (neighbors coord d))]
- [weight (in-value (hash-ref d neighbor))])
- (list weight coord neighbor))))
-
-;; part 1
-(define (find-path-weight d)
- (define grid (grid-graph d))
- (let-values ([(node-distances _) (dijkstra grid '(0 0))])
- (define xm (~>> d hash-keys (map first) (apply max)))
- (define ym (~>> d hash-keys (map second) (apply max)))
- (hash-ref node-distances (list xm ym))))
-
-(~> data
- find-path-weight
- time)
-
-;; part 2
-(define nine-cycle
- (in-cycle (inclusive-range 1 9)))
-
-(define (expand-data data)
- (for/fold ([cells (hash)])
- ([coord (in-list (hash-keys data))])
- (match-define (list x y) coord)
- (for*/fold ([cells cells])
- ([n (in-range 5)]
- [m (in-range 5)]
- [val (in-value (hash-ref data coord))])
- (hash-set cells
- (list (+ x (* n (add1 x-max)))
- (+ y (* m (add1 y-max))))
- (sequence-ref nine-cycle (+ val n m -1))))))
-
-(~> data
- expand-data
- find-path-weight
- time) \ No newline at end of file