You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
461 B
Racket
18 lines
461 B
Racket
4 years ago
|
#lang br
|
||
|
(require racket/file srfi/13 rackunit)
|
||
|
|
||
|
(define (seat-id seat)
|
||
|
(for/sum ([(c i) (in-indexed (string-reverse seat))]
|
||
|
#:when (memv c '(#\R #\B)))
|
||
|
(arithmetic-shift 1 i)))
|
||
|
|
||
|
(define seat-ids (map seat-id (file->lines "05.rktd")))
|
||
|
|
||
|
(check-equal? (apply max seat-ids) 915)
|
||
|
|
||
|
(check-equal?
|
||
|
(for/first ([first (sort seat-ids <)]
|
||
|
[second (cdr (sort seat-ids <))]
|
||
|
#:when (= 2 (- second first)))
|
||
|
(sub1 second))
|
||
|
699)
|