diff options
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)))) |