aoc2020/25.rkt

31 lines
853 B
Racket
Raw Normal View History

2020-12-25 05:21:17 +00:00
#lang curly-fn racket
2020-12-25 05:26:56 +00:00
(require "scripts/aoc.rkt" math/number-theory)
2020-12-25 05:21:17 +00:00
;; solution for day 25
(define *mod* 20201227)
2020-12-25 05:26:56 +00:00
(define *subject* 7)
2020-12-25 05:21:17 +00:00
(define (part1 input)
(match-define (list you door) input)
2020-12-25 05:26:56 +00:00
(with-modulus *mod*
(for/fold ([val 1] [you-loops #f] [door-loops #f] #:result (modexpt you door-loops))
([loops (in-range 0 +inf.0)] #:break (and you-loops door-loops))
(define new-val (mod* val *subject*))
(cond
[(= val you) (values new-val loops door-loops)]
[(= val door) (values new-val you-loops loops)]
[else (values new-val you-loops door-loops)]))))
2020-12-25 05:21:17 +00:00
;; parse input file
(define (parse fname)
(define input (file->lines fname))
(map string->number input))
(module+ main
(define input (parse "inputs/25"))
(answer 25 1 (time (part1 input)))
(aoc-finish)
(displayln "meow"))