From a88e8da779cd09c398723e4e87e79d945af0994e Mon Sep 17 00:00:00 2001 From: brian Date: Sat, 3 Aug 2024 13:33:43 -0700 Subject: initial commit to day 6 --- day1.scm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 day1.scm (limited to 'day1.scm') diff --git a/day1.scm b/day1.scm new file mode 100755 index 0000000..ca79a09 --- /dev/null +++ b/day1.scm @@ -0,0 +1,22 @@ +#!/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)))) -- cgit 1.4.1-2-gfad0