blob: a1c2d183981956279c9e636dc81ae6cf82c12b4e (
plain)
1
2
3
4
5
6
7
8
9
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)));
|