#!/usr/bin/env gosh (use file.util) (define (read-input filename) (map string->number (file->string-list filename))) (define (part1 input) (fold + 0 (map (lambda (x) (- (floor (/ x 3)) 2)) input))) (define (calculate-fuel weight acc) (if (< weight 9) acc (let ((fuel-weight (- (floor (/ weight 3)) 2))) (calculate-fuel fuel-weight (+ acc fuel-weight))))) (define (part2 input) (fold + 0 (map (lambda (x) (calculate-fuel x 0)) input))) (define (main args) (let ((input (read-input "inputs/day1.txt"))) (print (part1 input)) (print (part2 input))))