Advent of code 2022/1
Ajax Direct

Answer

Part 1 :
Part 2 :
// ==================================================
// > PART 1
// ==================================================

// Classic
$solution_1 = max(array_map(fn ($sub) => array_sum(explode("\n", trim($sub))), explode("\n\n", $input)));

// With tools
$solution_1 = $input->split("\n\n")->map(fn ($sub) => $sub->lines->sum())->max();


// ==================================================
// > PART 2
// ==================================================

// Classic
$calories = array_map(fn ($sub) => array_sum(explode("\n", trim($sub))), explode("\n\n", $input));
sort($calories);
$solution_2 = array_sum(array_slice($calories, -3));

// With tools
$solution_2 = $input->split("\n\n")->map(fn ($sub) => $sub->lines->sum())->sort()->slice(-3)->sum();