Day 07
Posted on Tue 07 December 2021 in aoc2021 • Tagged with js, python
See problem here.
The basic idea is to calculate the total cost
for some positions to position m
.
function fuel_cost(positions, m, method) {
var cost = 0;
for (var c of positions) {
if (method === "constant") {
cost += Math.abs(m - c);
}
else { // "step"
cost += Math.abs(m - c) * (Math.abs(m - c …
Continue reading