@sorawee has joined the channel
I didn’t search on part 2. Just use Rosette to do that for me :joy:
@wwall has joined the channel
for*
was sufficient
@ruyvalle has joined the channel
Here’s my day 1 solution. Feedback would be much appreciated :slightly_smiling_face: (define input-port
(open-input-file (expand-user-path "~/Downloads/AOCDay1In.txt")))
(define (calc-required-fuel mass)
(- (quotient mass 3) 2))
(for/sum ([str (in-lines input-port)])
(define num (string->number str))
(calc-required-fuel num))
My solution to day 1 parts 1 and 2 (define input-path (expand-user-path "~/Downloads/AOCDay1In.txt"))
(define (calc-required-fuel mass)
(- (quotient mass 3) 2))
(define (calc-required-fuel-rec mass)
(define (iter total mass)
(define required-fuel (calc-required-fuel mass))
(if (<= required-fuel 0)
total
(iter (+ total required-fuel) required-fuel)))
(iter 0 mass))
(define (solve-day1-part calc-func)
(with-input-from-file input-path
(thunk
(for/sum ([str (in-lines)])
(define num (string->number str))
(calc-func num)))))
(define (solve-day1-part1) (solve-day1-part calc-required-fuel))
(define (solve-day1-part2) (solve-day1-part calc-required-fuel-rec))
@popa.bogdanp has joined the channel
Bonus points for using Rosette - I guess! :)
It’s actually a pretty bad reason to use Rosette
In particular, if the program counter becomes a symbolic value, it will get stuck in an infinite loop and need symbolic reflection to counter that. And at that point I might as well just solve it with the “regular” method.
Luckily, input that I got didn’t cause pc to become symbolic, so ….
@philip.mcgrath has joined the channel
@d_run has joined the channel
@racket132 has joined the channel
My part two solution is horrid
well I used a mutable hashtable so maybe not that bad
Mutable hash too :slightly_smiling_face:
@bas has joined the channel