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 /aoc2023-racket/day-11 | |
parent | 6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff) | |
download | gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip |
sorting by language
Diffstat (limited to 'aoc2023-racket/day-11')
-rw-r--r-- | aoc2023-racket/day-11/day-11.rkt | 40 |
1 files changed, 0 insertions, 40 deletions
diff --git a/aoc2023-racket/day-11/day-11.rkt b/aoc2023-racket/day-11/day-11.rkt deleted file mode 100644 index dba617b..0000000 --- a/aoc2023-racket/day-11/day-11.rkt +++ /dev/null @@ -1,40 +0,0 @@ -#lang racket - -(require advent-of-code - threading) - -(struct posn (x y) #:transparent) - -(define input - (~> (fetch-aoc-input (find-session) 2023 11 #:cache #true) - (string-split "\n") - (map string->list _))) - -(define (get-empty-ranks grid) - (for/list ([(rank n) (in-indexed grid)] #:when (equal? '(#\.) (remove-duplicates rank))) - n)) - -(define (count-prior-empty-ranks rank empty-ranks) - (~> empty-ranks - (takef (curryr < rank)) - length)) - -(define empty-rows (get-empty-ranks input)) -(define empty-columns (get-empty-ranks (apply map list input))) ;; transpose - -(define (sum-of-star-distances in expand-by) - (define stars - (for*/list ([(row x) (in-indexed in)] - [(col y) (in-indexed row)] - #:when (equal? col #\#)) - (posn (+ x (* (sub1 expand-by) (count-prior-empty-ranks x empty-rows))) - (+ y (* (sub1 expand-by) (count-prior-empty-ranks y empty-columns)))))) - (for/sum ([star-pair (in-combinations stars 2)]) - (match-define (list (posn x1 y1) (posn x2 y2)) star-pair) - (+ (abs (- x1 x2)) (abs (- y1 y2))))) - -;; part 1 -(sum-of-star-distances input 2) - -;; part 2 -(sum-of-star-distances input 1000000) |