aboutsummaryrefslogtreecommitdiff
path: root/aoc2022/day-08/day-08.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 /aoc2022/day-08/day-08.rkt
parent6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff)
downloadgleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz
gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip
sorting by language
Diffstat (limited to 'aoc2022/day-08/day-08.rkt')
-rw-r--r--aoc2022/day-08/day-08.rkt56
1 files changed, 0 insertions, 56 deletions
diff --git a/aoc2022/day-08/day-08.rkt b/aoc2022/day-08/day-08.rkt
deleted file mode 100644
index 6b60eca..0000000
--- a/aoc2022/day-08/day-08.rkt
+++ /dev/null
@@ -1,56 +0,0 @@
-#lang racket
-
-(require advent-of-code)
-
-(struct posn (r c) #:transparent)
-
-(define (make-tree-grid data)
- (for*/hash ([(row r) (in-indexed data)] [(col c) (in-indexed (in-string row))])
- (values (posn r c) (string->number (string col)))))
-
-(define tree-grid (make-tree-grid (in-lines (open-aoc-input (find-session) 2022 8))))
-
-;; part 1
-
-(define (can-see-to-outside? p height dr dc h)
- (match-define (posn r c) p)
- (not (for/first ([n (in-naturals 1)]
- #:do [(define p* (posn (+ r (* n dr)) (+ c (* n dc))))]
- #:break (not (hash-has-key? h p*))
- #:when (<= height (hash-ref h p*)))
- #true)))
-
-(define (visible-in-any-direction? p height h)
- (for*/or ([dr (in-list '(-1 0 1))] [dc (in-list '(-1 0 1))] #:when (= 1 (abs (+ dr dc))))
- (can-see-to-outside? p height dr dc h)))
-
-(define (count-visible-trees trees)
- (for/sum ([(tree-posn height) (in-hash trees)])
- (cond
- [(visible-in-any-direction? tree-posn height trees) 1]
- [else 0])))
-
-(count-visible-trees tree-grid)
-
-;; part 2
-
-(define (scenic-score-in-direction p height dr dc h)
- (match-define (posn r c) p)
- (define score
- (for/last ([n (in-naturals 1)]
- #:do [(define p* (posn (+ r (* n dr)) (+ c (* n dc))))]
- #:break (not (hash-has-key? h p*))
- #:final (<= height (hash-ref h p*)))
- n))
- (if (not score) 0 score))
-
-(define (scenic-score p height h)
- (for*/product ([dr (in-list '(-1 0 1))] [dc (in-list '(-1 0 1))] #:when (= 1 (abs (+ dr dc))))
- (scenic-score-in-direction p height dr dc h)))
-
-(define (find-best-scenic-score trees)
- (apply max
- (for/list ([(tree-posn height) (in-hash trees)])
- (scenic-score tree-posn height trees))))
-
-(find-best-scenic-score tree-grid)