aboutsummaryrefslogtreecommitdiff
path: root/aoc2023-other/day-16/day-16.rkt
diff options
context:
space:
mode:
authorHunky Jimpjorps <thechairman@thechairman.info>2024-02-02 17:05:12 -0500
committerHunky Jimpjorps <thechairman@thechairman.info>2024-02-02 17:05:12 -0500
commit48e35ad3b0b0c62f936784e4aca70b17c3b0e3f9 (patch)
treef59a13e0b5e80ab925220b4488c6e36b1bec660a /aoc2023-other/day-16/day-16.rkt
parent87e9ab25ff70e215b537939a4bc23ab101f41dbe (diff)
downloadgleam_aoc-48e35ad3b0b0c62f936784e4aca70b17c3b0e3f9.tar.gz
gleam_aoc-48e35ad3b0b0c62f936784e4aca70b17c3b0e3f9.zip
renaming
Diffstat (limited to 'aoc2023-other/day-16/day-16.rkt')
-rw-r--r--aoc2023-other/day-16/day-16.rkt70
1 files changed, 0 insertions, 70 deletions
diff --git a/aoc2023-other/day-16/day-16.rkt b/aoc2023-other/day-16/day-16.rkt
deleted file mode 100644
index 4a70de8..0000000
--- a/aoc2023-other/day-16/day-16.rkt
+++ /dev/null
@@ -1,70 +0,0 @@
-#lang racket
-
-(require advent-of-code
- threading)
-
-(struct posn (r c) #:transparent)
-(struct light (posn dir) #:transparent)
-
-(define input (fetch-aoc-input (find-session) 2023 16 #:cache #true))
-
-(define grid
- (for*/hash ([(row r) (in-indexed (string-split input "\n"))]
- [(cell c) (in-indexed (in-string row))])
- (values (posn r c) cell)))
-
-(define/match (move _l)
- [((light (posn r c) 'up)) (light (posn (sub1 r) c) 'up)]
- [((light (posn r c) 'right)) (light (posn r (add1 c)) 'right)]
- [((light (posn r c) 'left)) (light (posn r (sub1 c)) 'left)]
- [((light (posn r c) 'down)) (light (posn (add1 r) c) 'down)])
-
-(define/match (transform l _cell)
- [(_ #\.) l]
- [(_ 'off) '()]
-
- [((light _ (or 'up 'down)) #\|) l]
- [((light _ (or 'left 'right)) #\-) l]
-
- [((light p 'left) #\/) (light p 'down)]
- [((light p 'down) #\/) (light p 'left)]
- [((light p 'right) #\/) (light p 'up)]
- [((light p 'up) #\/) (light p 'right)]
-
- [((light p 'left) #\\) (light p 'up)]
- [((light p 'up) #\\) (light p 'left)]
- [((light p 'right) #\\) (light p 'down)]
- [((light p 'down) #\\) (light p 'right)]
-
- [((light p (or 'left 'right)) #\|) (list (light p 'up) (light p 'down))]
- [((light p (or 'up 'down)) #\-) (list (light p 'left) (light p 'right))])
-
-;; part 1
-(define (get-energized start)
- (for/fold ([energized (set)]
- [previously-visited (set)]
- [beam-tips (set start)]
- #:result (set-count energized))
- ([_ (in-naturals)])
- (define next-positions
- (list->set
- (flatten (for/list ([b (in-set beam-tips)])
- (~> b move ((λ (b) (transform b (hash-ref grid (light-posn b) 'off)))))))))
- (define all-visited (set-union previously-visited next-positions))
- (define next-energized (set-union energized (list->set (set-map next-positions light-posn))))
- #:break (equal? previously-visited all-visited)
- (values next-energized all-visited (set-subtract next-positions previously-visited))))
-
-(get-energized (light (posn 0 -1) 'right))
-
-;; part 2
-(define rows (~> input (string-split "\n") length))
-(define cols (~> input (string-split #rx"\n.*") first string-length))
-
-(define all-starting-positions
- (append (map (λ (r) (light (posn r -1) 'right)) (range rows))
- (map (λ (r) (light (posn r cols) 'left)) (range rows))
- (map (λ (c) (light (posn -1 c) 'down)) (range cols))
- (map (λ (c) (light (posn rows c) 'up)) (range cols))))
-
-(get-energized (argmax get-energized all-starting-positions)) \ No newline at end of file