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
333 B
Plaintext
11 lines
333 B
Plaintext
3 years ago
|
load("descriptive")$
|
||
3 years ago
|
load("in.mac")$ /* Should define `input` list of numbers. */
|
||
3 years ago
|
|
||
|
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)));
|
||
|
|