Add cl-interpol
[adventofcode2020.git] / src / day00.lisp
1 (in-package #:adventofcode2020)
2
3 (defun simple-fuel (mass)
4 (- (floor (/ mass 3))
5 2))
6
7 (defun complex-fuel (mass)
8 (loop with m = (simple-fuel mass)
9 while (> m 0) sum m
10 do (setf m (simple-fuel m))))
11
12 (day 00 input
13 (let ((modules (int-list-from input)))
14 (part1 (reduce #'+ (mapcar #'simple-fuel modules)))
15 (part2 (reduce #'+ (mapcar #'complex-fuel modules)))))
16
17 (def-suite day00)
18 (in-suite day00)
19
20 (test simple-fuel
21 (is (equal
22 '(2 2 654 33583)
23 (mapcar #'simple-fuel '(12 14 1969 100756)))))
24
25 (test complex-fuel
26 (is (equal
27 '(2 966 50346)
28 (mapcar #'complex-fuel '(14 1969 100756)))))
29
30 (run! 'day00)