shadow wizard day6 gang

This commit is contained in:
xenia 2023-12-06 01:29:20 -05:00
parent a335daee00
commit 08fbef4592
3 changed files with 49 additions and 0 deletions

45
6.rkt Normal file
View File

@ -0,0 +1,45 @@
#lang curly-fn racket
(require "scripts/aoc.rkt")
;; solution for day 6
(define (do-race total-time hold-time)
(define rem-time (- total-time hold-time))
(* rem-time hold-time))
(define (part1 input)
(apply
*
(for/list ([time (in-list (first input))] [dist (in-list (second input))])
(for/fold ([cnt 0]) ([hold (in-range time)])
(define res (do-race time hold))
(if (> res dist)
(add1 cnt)
cnt)))))
(define (cvt l)
(string->number (apply string-append (map number->string l))))
(define (part2 input)
(define time (cvt (first input)))
(define dist (cvt (second input)))
(for/fold ([cnt 0]) ([hold (in-range time)])
(define res (do-race time hold))
(if (> res dist)
(add1 cnt)
cnt)))
(define (parse fname)
(match-define (list time-str dist-str) (file->lines fname))
(list (map string->number (rest (string-split time-str)))
(map string->number (rest (string-split dist-str)))))
; (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"))

2
inputs/6 Normal file
View File

@ -0,0 +1,2 @@
Time: 46 85 75 82
Distance: 208 1412 1257 1410

2
inputs/6-test1 Normal file
View File

@ -0,0 +1,2 @@
Time: 7 15 30
Distance: 9 40 200