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-14/day-14.rkt | |
parent | 6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff) | |
download | gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip |
sorting by language
Diffstat (limited to 'aoc2023-racket/day-14/day-14.rkt')
-rw-r--r-- | aoc2023-racket/day-14/day-14.rkt | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/aoc2023-racket/day-14/day-14.rkt b/aoc2023-racket/day-14/day-14.rkt deleted file mode 100644 index d0b7cad..0000000 --- a/aoc2023-racket/day-14/day-14.rkt +++ /dev/null @@ -1,49 +0,0 @@ -#lang racket - -(require advent-of-code - threading - "../../jj-aoc.rkt") - -(define input - (~> (fetch-aoc-input (find-session) 2023 14 #:cache #true) - string-split - (map string->list _) - transpose)) - -(define (roll-boulders board) - (for/list ([col (in-list board)]) - (~> col (chunks-by (curry equal? #\#)) (append-map (curryr sort char>?) _)))) - -(define (score board) - (for*/sum ([col (in-list board)] - [(row n) (in-indexed (reverse col))] - #:when (equal? row #\O)) - (add1 n))) - -;; part 1 -(~> input - roll-boulders - score) - -;; part 2 -(define (rotate-board xss) - (~> xss - (map reverse _) - transpose)) - -(define (full-cycle board) - (foldl (λ (_ acc) (~> acc roll-boulders rotate-board)) board (range 4))) - -(define (spin-to-win board) - (define cache (make-hash)) - (define (do-spin board n) - (match (hash-ref cache board 'not-found) - ['not-found - (hash-set! cache board n) - (do-spin (full-cycle board) (sub1 n))] - [seen - (define to-end (modulo n (- seen n))) - (score (foldl (λ (_ acc) (full-cycle acc)) board (range to-end)))])) - (do-spin board 1000000000)) - -(~> input spin-to-win) |