diff options
author | brian <brianmchu42@gmail.com> | 2024-08-03 13:33:43 -0700 |
---|---|---|
committer | brian <brianmchu42@gmail.com> | 2024-08-03 13:33:43 -0700 |
commit | a88e8da779cd09c398723e4e87e79d945af0994e (patch) | |
tree | 0be5a89e050f088ebc166433c4ce251d43062bb4 /day1.scm | |
download | AdventOfCode2019-a88e8da779cd09c398723e4e87e79d945af0994e.tar.gz |
initial commit to day 6 main
Diffstat (limited to 'day1.scm')
-rwxr-xr-x | day1.scm | 22 |
1 files changed, 22 insertions, 0 deletions
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)))) |