Advent of code 2023/4
Ajax Direct

Answer

Part 1 :
Part 2 :
$wins = $input->lines->map(function ($l) {
    [$_, $l] = $l->split(":");
    [$winners, $have] = $l->split("|");
    return $have->numbers()->keep($winners->numbers())->count();
});

// ==================================================
// > PART 1
// ==================================================
$solution_1 = $wins->map(fn ($w) => $w ? 2 ** ($w - 1) : 0)->sum();

// ==================================================
// > PART 2
// ==================================================
$cards = $wins->map(fn () => 1);
foreach ($cards as $i => $card) {
    for ($j = 1; $j <= $wins[$i]; $j++) {
        $cards[$i + $j] += $card;
    }
}
$solution_2 = $cards->sum();