Advent of Code 2020 solutions in Racket, I guess
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
699 B

#lang racket
(require "lib/common.rkt"
math/number-theory)
(define (parse prt)
(map string->number (port->lines prt)))
(define (loop-sizes card door)
(for/fold ([cl #f] [dl #f])
([i (in-naturals)]
#:break (and cl dl))
(define n (modular-expt 7 i 20201227))
(cond [(= n card) (values i dl)]
[(= n door) (values cl i)]
[else (values cl dl)])))
(define (day25a input)
(match-define (list card door) input)
(define-values (cl dl) (loop-sizes card door))
(modular-expt card dl 20201227))
(module+ main
(call-with-input-file "data/day25.txt"
(λ (prt)
(define input (parse prt))
(answer 25 1 (day25a input)))))