Hazel Levine 8 months ago
parent
commit
9e52241aa4
Signed by: hazel GPG Key ID: 1884029A28789A62
  1. 1
      .gitignore
  2. 52
      day11-viz.rkt

1
.gitignore

@ -67,3 +67,4 @@ flycheck_*.el
.envrc
.status.rktd
viz/*

52
day11-viz.rkt

@ -0,0 +1,52 @@
#lang racket
(require "day11.rkt"
2htdp/image
memoize)
;; warning: slow as fuck
;; convert -delay 50 viz-*.png -loop 0 viz.gif
(define empty-pixel (square 10 'solid 'green))
(define occupied-pixel (square 10 'solid 'red))
(define floor-pixel (square 10 'solid 'black))
(define (seat->pixel seat)
(match seat
[#\L empty-pixel]
[#\# occupied-pixel]
[#\. floor-pixel]))
(define (draw-row row)
(define/memo (draw-row/iter lst)
(cond [(empty? lst) empty-image]
[else (beside (seat->pixel (first lst))
(draw-row/iter (rest lst)))]))
(draw-row/iter (vector->list row)))
(define (draw-board board)
(define/memo (draw-board/iter lst)
(cond [(empty? lst) empty-image]
[else (above (draw-row (first lst))
(draw-board/iter (rest lst)))]))
(draw-board/iter (vector->list board)))
(define (run-viz/a board [last-board #f] [n 0])
(save-image (draw-board board) (format "viz/a/viz-~a.png" n))
(unless (equal? board last-board)
(run-viz/a ((tick-state count-neighbors/a 4) board)
board
(add1 n))))
(define (run-viz/b board [last-board #f] [n 0])
(save-image (draw-board board) (format "viz/b/viz-~a.png" n))
(unless (equal? board last-board)
(run-viz/b ((tick-state count-neighbors/b 5) board)
board
(add1 n))))
(module+ main
(call-with-input-file "data/day11.txt"
(lambda (prt)
(define input (preprocess prt))
(void (run-viz/a input))
(void (run-viz/b input)))))
Loading…
Cancel
Save