Browse Source

day 11

canon
Hazel Levine 8 months ago
parent
commit
e926ad4639
Signed by: hazel GPG Key ID: 1884029A28789A62
  1. 10
      data/day11.test.txt
  2. 95
      data/day11.txt
  3. 104
      day11.rkt

10
data/day11.test.txt

@ -0,0 +1,10 @@
L.LL.LL.LL
LLLLLLL.LL
L.L.L..L..
LLLL.LL.LL
L.LL.LL.LL
L.LLLLL.LL
..L.L.....
LLLLLLLLLL
L.LLLLLL.L
L.LLLLL.LL

95
data/day11.txt

@ -0,0 +1,95 @@
LLLLLLLL.LLLL.LLLLL.LLLLLLLLLLLLLL.LLLLLLLLLLLLLL.LLLLL.LLLLLLLLLLLLLL.LLLLLLL.LLLLLL.LLLLLLLLLL.L
LLLLLLLLLLLLLLLLLLL.L.LL.LLL.LLLLL.LLLLLLLLLLL.LL.LLLLL.LLLLLLLL.LLLLLLLLL.LLL.LLLLLLLLLLLLLLLLLLL
LLLLLLLLLLLLL.LLLLLLLLLLLLLL.LL.LL.LLLLLLL.LLLLLL.LLLLLLLLL.LLLL.LLLLL.LLLLLLL.LLLLLL.LLLLLLLLLLLL
LLLLLLLL.LLLL.LLLLL..LLLLLLL.L.LLL.LLLLLLL.LLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLLLL.LLLLLLLLLLLL
LLLLLL.L.LLLL.L.LLL.LLLLLLLLLLLLLL.LLL.LLL.LLLLLL.LLLLL.LLLLLLLLLLLLLL.LLLLLLL.LLLLLL.LLLLLLLLLLLL
LLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLL.LLLLLLL.LLLLLLLLLLLLLLLLLLLLL.LLLLL.LLLLL.L.LLLLLLLLLLLLLLLLLLL
L...LLL...L....L......L..L....LL...L.LLL...............L..LL.LLL.LL..L..........L......L.L....L.LL
LLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLL.L.LLLL.LLLLLLL.LLLLLLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLL.LLLLLLLLLL
LLLLLLLL.LLLL.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@ -0,0 +1,104 @@
#lang racket
(require "lib/common.rkt")
(provide (all-defined-out))
(define (count-occupied board)
(for/sum ([row (in-vector board)])
(vector-count (lambda (v) (char=? v #\#)) row)))
(define (board-dim board)
(cons (vector-length (vector-ref board 0))
(vector-length board)))
(define (board-set! board x y val)
(vector-set! (vector-ref board y) x val))
(define (board-ref board x y)
(vector-ref (vector-ref board y) x))
(define (board-copy board)
(vector-copy (vector-map vector-copy board)))
(define (dbg-board board)
(for ([row (in-vector board)])
(displayln (vector->list row)))
board)
(define (occupied? board x y)
(char=? (board-ref board x y) #\#))
(define (unoccupied? board x y)
(char=? (board-ref board x y) #\L))
(define (floor? board x y)
(char=? (board-ref board x y) #\.))
(define (count-neighbors/a board x y)
(match-define (cons m n) (board-dim board))
(for*/sum ([dx (in-range (sub1 x) (+ 2 x))]
[dy (in-range (sub1 y) (+ 2 y))]
#:unless (and (= dx x) (= dy y))
#:unless (or (< dx 0) (< dy 0)
(>= dx m)
(>= dy n)))
(if (occupied? board dx dy) 1 0)))
(define (count-neighbors/b board x y)
(match-define (cons m n) (board-dim board))
(define (occupied?/b sx sy dx dy)
(cond [(or (< sx 0) (< sy 0) (>= sx m) (>= sy n)) #f]
[else
(define val (board-ref board sx sy))
(match val
[#\# #t]
[#\L #f]
[#\. (occupied?/b (+ sx dx) (+ sy dy) dx dy)])]))
(for/sum ([path (in-list '((1 . 1) (1 . 0) (1 . -1)
(0 . 1) (0 . -1)
(-1 . 1) (-1 . 0) (-1 . -1)))])
(match-define (cons dx dy) path)
(if (occupied?/b (+ dx x) (+ dy y) dx dy) 1 0)))
(define ((tick-state count-neighbors num-neighbors) board)
(match-define (cons m n) (board-dim board))
(define res (board-copy board))
(for* ([i (in-range 0 m)]
[j (in-range 0 n)])
(define neighbors (count-neighbors board i j))
(cond [(floor? board i j) (void)]
[(and (unoccupied? board i j)
(zero? neighbors))
(board-set! res i j #\#)]
[(and (occupied? board i j)
(>= neighbors num-neighbors))
(board-set! res i j #\L)]))
res)
(define (fix f arg)
(define res (f arg))
(if (equal? res arg)
arg
(fix f res)))
(define (day11a input)
(count-occupied (fix (tick-state count-neighbors/a 4) input)))
(define (day11b input)
(count-occupied (fix (tick-state count-neighbors/b 5) input)))
(define (preprocess prt)
(list->vector (map (compose1 list->vector string->list)
(port->lines prt))))
(module+ main
(call-with-input-file "data/day11.txt"
(lambda (prt)
(define input (preprocess prt))
(answer 11 1 (day11a input))
(answer 11 2 (day11b input)))))
(module+ test
(require rackunit)
(call-with-input-file "data/day11.test.txt"
(lambda (prt)
(define input (preprocess prt))
(check-equal? (count-occupied input) 0)
(check-equal? (board-dim input) (cons 10 10))
(check-equal? (day11a input) 37)
(check-equal? (day11b input) 26))))
Loading…
Cancel
Save