40 lines
1.2 KiB
Racket
40 lines
1.2 KiB
Racket
#lang curly-fn racket
|
|
|
|
(require "scripts/aoc.rkt")
|
|
|
|
;; solution for day 5
|
|
|
|
;; helper functions here
|
|
|
|
(define (part1 input)
|
|
(apply max
|
|
(for/list ([line (in-list input)])
|
|
(match-define (list _ rowstr colstr) (regexp-match #px"^([FB]{7})([LR]{3})$" line))
|
|
(define row (string->number (string-replace (string-replace rowstr "F" "0") "B" "1") 2))
|
|
(define col (string->number (string-replace (string-replace colstr "L" "0") "R" "1") 2))
|
|
(+ (* row 8) col))))
|
|
|
|
(define (part2 input)
|
|
(define seats
|
|
(for/list ([line (in-list input)])
|
|
(match-define (list _ rowstr colstr) (regexp-match #px"^([FB]{7})([LR]{3})$" line))
|
|
(define row (string->number (string-replace (string-replace rowstr "F" "0") "B" "1") 2))
|
|
(define col (string->number (string-replace (string-replace colstr "L" "0") "R" "1") 2))
|
|
(+ (* row 8) col)))
|
|
|
|
(for/first ([id (in-range (apply min seats) (apply max seats))]
|
|
#:when (and (not (member id seats))
|
|
(member (add1 id) seats)
|
|
(member (sub1 id) seats)))
|
|
id))
|
|
|
|
(module+ main
|
|
(define input (file->lines "inputs/5"))
|
|
;; part 1
|
|
(answer 5 1 (part1 input))
|
|
|
|
;; part 2
|
|
(answer 5 2 (part2 input))
|
|
|
|
(displayln "meow"))
|