#lang curly-fn racket (require "scripts/aoc.rkt" math/number-theory) ;; solution for day 25 (define *mod* 20201227) (define *subject* 7) (define (part1 input) (match-define (list you door) input) (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)])))) ;; 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"))