1
0
Fork 0
adventofcode/src/05.rkt

19 lines
541 B
Racket
Raw Normal View History

2020-12-05 06:20:23 +00:00
#lang racket
2020-12-05 06:37:36 +00:00
(require racket/set
"../lib.rkt")
2020-12-05 06:20:23 +00:00
2020-12-05 06:37:36 +00:00
(define (string->seat str)
(string->number (string-append "#b" (regexp-replaces str '([#rx"F" "0"] [#rx"B" "1"] [#rx"L" "0"] [#rx"R" "1"])))))
2020-12-05 06:20:23 +00:00
2020-12-05 06:37:36 +00:00
(define input (map string->seat (problem-input 5)))
2020-12-05 06:20:23 +00:00
2020-12-05 06:37:36 +00:00
(define-values (part1 part2)
(let* ([minimum ($ min input)]
[maximum ($ max input)]
2020-12-05 06:37:36 +00:00
[seats (list->set (range minimum (add1 maximum)))]
[filled (list->set input)])
(values maximum (set-first (set-subtract seats filled)))))
2020-12-05 06:20:23 +00:00
(show-solution part1 part2)