function solve($players_count, $last_marble) {
$scores = array_fill_keys(range(0, $players_count - 1), 0);
$circle = new LinkedList(0, true);
$current = $circle->getHead();
for ($marble = 1; $marble < $last_marble; $marble++) {
$player = $marble % $players_count;
if (!($marble % 23)) {
for ($i = 0; $i < 7; $i++) $current = $current->getPrev();
$scores[$player] += $marble + $current->getValue();
$current->remove();
$current = $current->getNext();
continue;
}
$current = $current->getNext()->insertAfter($marble);
}
return max($scores);
}
// ==================================================
// > PART 1
// ==================================================
[$players_count, $last_marble] = $input->numbers();
$solution_1 = solve($players_count, $last_marble);
// ==================================================
// > PART 2
// ==================================================
$solution_2 = solve($players_count, $last_marble * 100);