1
0
Fork 0
adventofcode/src/05.rkt

22 lines
573 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)
2020-12-08 04:49:06 +00:00
(~>> str
(regexp-replaces _ '([#rx"F" "0"] [#rx"B" "1"] [#rx"L" "0"] [#rx"R" "1"]))
(string-append "#b")
string->number))
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)
2020-12-08 04:49:06 +00:00
(let* ([minimum (apply min input)]
[maximum (apply 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)