day 25: all done....
This commit is contained in:
parent
c0c11034af
commit
f782867296
|
@ -0,0 +1,53 @@
|
||||||
|
#lang curly-fn racket
|
||||||
|
|
||||||
|
(require "scripts/aoc.rkt")
|
||||||
|
|
||||||
|
;; solution for day 25
|
||||||
|
|
||||||
|
(define *mod* 20201227)
|
||||||
|
|
||||||
|
(define (loop subject times)
|
||||||
|
(for/fold ([val 1]) ([_ (in-range (+ 0 times))])
|
||||||
|
(remainder (* val subject) *mod*)))
|
||||||
|
|
||||||
|
(define (part1 input)
|
||||||
|
(match-define (list you door) input)
|
||||||
|
(define you-loops #f)
|
||||||
|
(define door-loops #f)
|
||||||
|
(for/fold ([val 1]) ([loops (in-range 0 +inf.0)] #:break (and you-loops door-loops))
|
||||||
|
(when (= val you)
|
||||||
|
(set! you-loops loops))
|
||||||
|
(when (= val door)
|
||||||
|
(set! door-loops loops))
|
||||||
|
(remainder (* val 7) *mod*))
|
||||||
|
; (displayln you-loops)
|
||||||
|
; (displayln door-loops)
|
||||||
|
(displayln you-loops)
|
||||||
|
(displayln (loop 7 you-loops))
|
||||||
|
(displayln you)
|
||||||
|
(displayln door-loops)
|
||||||
|
(displayln (loop 7 door-loops))
|
||||||
|
(displayln door)
|
||||||
|
; (displayln (loop door-loops you-loops))
|
||||||
|
; (displayln (loop you-loops door-loops))
|
||||||
|
; (displayln (loop 17807724 8))
|
||||||
|
; (displayln (loop 5764801 11))
|
||||||
|
(loop you door-loops))
|
||||||
|
; (part1 (list 5764801 17807724))
|
||||||
|
; (error)
|
||||||
|
|
||||||
|
;; parse input file
|
||||||
|
(define (parse fname)
|
||||||
|
(define input (file->lines fname))
|
||||||
|
(map string->number input))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(require rackunit)
|
||||||
|
;; tests here
|
||||||
|
(displayln "no tests :("))
|
||||||
|
|
||||||
|
(module+ main
|
||||||
|
(define input (parse "inputs/25"))
|
||||||
|
(answer 25 1 (time (part1 input)))
|
||||||
|
(aoc-finish)
|
||||||
|
(displayln "meow"))
|
|
@ -73,6 +73,9 @@
|
||||||
'answer-correct]
|
'answer-correct]
|
||||||
[(pregexp #px"That's not the right answer") 'answer-incorrect]
|
[(pregexp #px"That's not the right answer") 'answer-incorrect]
|
||||||
[(pregexp #px"You gave an answer too recently") 'rate-limited]
|
[(pregexp #px"You gave an answer too recently") 'rate-limited]
|
||||||
|
[(pregexp #px"fifty stars")
|
||||||
|
(aoc-set-complete! day part)
|
||||||
|
'year-complete]
|
||||||
[(pregexp #px"Did you already complete it?")
|
[(pregexp #px"Did you already complete it?")
|
||||||
(aoc-set-complete! day part)
|
(aoc-set-complete! day part)
|
||||||
'already-completed]
|
'already-completed]
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
;; utilities for every challenge script
|
;; utilities for every challenge script
|
||||||
|
|
||||||
(require "aoc-lib.rkt" threading syntax/parse/define (for-syntax racket/syntax) graph)
|
(require "aoc-lib.rkt" threading syntax/parse/define (for-syntax racket/syntax) graph)
|
||||||
(provide answer dbg memoize define/memoized
|
(provide answer aoc-finish dbg memoize define/memoized
|
||||||
band bor bxor bnot bshl bshr bset? bfield
|
band bor bxor bnot bshl bshr bset? bfield
|
||||||
maximum-bipartite-matching/stable
|
maximum-bipartite-matching/stable
|
||||||
(all-from-out threading syntax/parse/define graph)
|
(all-from-out threading syntax/parse/define graph)
|
||||||
|
@ -63,3 +63,13 @@
|
||||||
(~a answer)))
|
(~a answer)))
|
||||||
(printf "server responded: ~a\n" resp)]
|
(printf "server responded: ~a\n" resp)]
|
||||||
[_ (printf "not submitting\n")])))
|
[_ (printf "not submitting\n")])))
|
||||||
|
|
||||||
|
;; submit 25 part 2
|
||||||
|
(define (aoc-finish)
|
||||||
|
(unless (aoc-complete? 25 1)
|
||||||
|
(error "submit 25.1 first"))
|
||||||
|
(unless (aoc-complete? 25 2)
|
||||||
|
(printf "submitting done for 25.2...\n")
|
||||||
|
(define resp
|
||||||
|
(aoc-submit-answer (getenv "AOC_YEAR") "25" (getenv "AOC_SESSION") "2" "done"))
|
||||||
|
(printf "server responded: ~a\n" resp)))
|
||||||
|
|
Loading…
Reference in New Issue