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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
aoc-racket/2020/05.rkt

18 lines
461 B
Racket

#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)