aboutsummaryrefslogtreecommitdiffstats
path: root/year2021/day7/maxima.mac
diff options
context:
space:
mode:
Diffstat (limited to 'year2021/day7/maxima.mac')
-rw-r--r--year2021/day7/maxima.mac10
1 files changed, 10 insertions, 0 deletions
diff --git a/year2021/day7/maxima.mac b/year2021/day7/maxima.mac
new file mode 100644
index 0000000..a1c2d18
--- /dev/null
+++ b/year2021/day7/maxima.mac
@@ -0,0 +1,10 @@
+load("descriptive")$
+load("in.mac")$ /* Should define `input` list of numbers. */
+
+calcfuel(pos, distmod) :=
+ lreduce("+", map(lambda([n], distmod(abs(pos - n))), input))$
+
+calcfuel(median(input), lambda([x],x));
+calcfuel(floor(mean(input)), lambda([x], (x*(x+1)/2)));
+calcfuel(floor(mean(input)) + 1, lambda([x], (x*(x+1)/2)));
+