You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

11 lines
339 B
Plaintext

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)));