diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2021-12-07 14:45:32 -0500 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2021-12-07 14:45:32 -0500 |
commit | a1af4e9dec325a3fff03140999ac737c983d1f49 (patch) | |
tree | 278f65db1f42a3aa3085d8aa9b7d52416976f590 /day7/maxima.mx | |
parent | 803b9b677fcfc9ca38e1231fcf5def0f35782936 (diff) |
day7: improve part1; add maxima solutions
Diffstat (limited to 'day7/maxima.mx')
-rw-r--r-- | day7/maxima.mx | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/day7/maxima.mx b/day7/maxima.mx new file mode 100644 index 0000000..4625fdc --- /dev/null +++ b/day7/maxima.mx @@ -0,0 +1,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))); + |