blob: 4625fdca66725f719a479625ad32184053792929 (
plain)
1
2
3
4
5
6
7
8
9
10
|
load("descriptive")$
batchload("./in.mx")$ /* 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)));
|