Advent of code 2021/6
Ajax Direct

Answer 1ms

Part 1 : 366057 Part 2 : 1653559299811
function solve($days) {
    global $input;
    $fish = $input->numbers->occurrences();

    for ($i = 0; $i < $days; $i++) {
        $fish2 = [];
        $new = 0;

        foreach ($fish as $d=>$f) {
            $nd = int($d) - 1;
            $new += $nd < 0 ? $fish[$d] : 0;
            $nd = $nd < 0 ? 6 : $nd;
            $fish2[$nd] = ($fish2[$nd] ?? 0) + $fish[$d];
        }
        $fish = $fish2;
        $fish[8] = $new;
    }

    return set($fish)->sum();
}

// ==================================================
// > SOLUTIONS
// ==================================================
$solution_1 = solve(80);
$solution_2 = solve(256);