Advent of code 2021/7
Ajax Direct

Answer

Part 1 :
Part 2 :
function solve($calc_fuel) {
    global $input;

    $pos = $input->numbers()->occurrences();
    $fuel = [];

    for ($i = $pos->keys()->min(); $i <= $pos->keys()->max(); $i++) {
        $fuel[$i] = 0;
        foreach ($pos as $p=>$n) {
            $fuel[$i] += $calc_fuel(abs($i - $p)) * $n;
        }
    }

    return set($fuel)->min();
}

// ==================================================
// > SOLUTIONS
// ==================================================
$solution_1 = solve(fn ($f) => $f);
$solution_2 = solve(fn ($f) => $f * ($f + 1) / 2);