2023-12-06 06:29:20 +00:00
|
|
|
#lang curly-fn racket
|
|
|
|
|
2023-12-06 06:48:14 +00:00
|
|
|
(require "scripts/aoc.rkt" math/number-theory)
|
2023-12-06 06:29:20 +00:00
|
|
|
|
|
|
|
;; solution for day 6
|
|
|
|
|
2023-12-06 06:48:14 +00:00
|
|
|
(define (do-race time dist)
|
2023-12-06 07:21:06 +00:00
|
|
|
(match-define (list lower upper)
|
|
|
|
(quadratic-solutions 1 (- time) dist))
|
|
|
|
(inexact->exact (- (ceiling upper) (add1 (floor lower)))))
|
2023-12-06 06:29:20 +00:00
|
|
|
|
|
|
|
(define (part1 input)
|
2023-12-06 06:48:14 +00:00
|
|
|
(for/product ([time (in-list (first input))]
|
|
|
|
[dist (in-list (second input))])
|
|
|
|
(do-race time dist)))
|
|
|
|
|
|
|
|
(define (number-concat l)
|
|
|
|
(~>> (map number->string l)
|
|
|
|
(apply string-append)
|
|
|
|
string->number))
|
2023-12-06 06:29:20 +00:00
|
|
|
|
|
|
|
(define (part2 input)
|
2023-12-06 06:48:14 +00:00
|
|
|
(apply do-race (map number-concat input)))
|
2023-12-06 06:29:20 +00:00
|
|
|
|
|
|
|
(define (parse fname)
|
2023-12-06 06:48:14 +00:00
|
|
|
(map #{map string->number (rest (string-split %))}
|
|
|
|
(file->lines fname)))
|
2023-12-06 06:29:20 +00:00
|
|
|
|
|
|
|
; (dbg (part1 (parse "inputs/6-test1")))
|
|
|
|
; (error)
|
|
|
|
|
|
|
|
(module+ main
|
|
|
|
(define input (parse "inputs/6"))
|
|
|
|
(answer 6 1 (time (part1 input)))
|
|
|
|
(answer 6 2 (time (part2 input)))
|
|
|
|
(displayln "meow"))
|