Part 2 :
$nums = $input->numbers();
$last = $nums->reduce(function ($carry, $item, $key) {
$carry[$item] = $key;
return $carry;
}, [], true);
unset($last[$nums->last()]);
$prev = $nums->last();
for ($i = count($nums); $i < 30_000_000; $i++) {
$num = isset($last[$prev]) ? $i - 1 - $last[$prev] : 0;
$last[$prev] = $i - 1;
$nums[] = $prev = $num;
}
$solution_1 = $nums[2019];
$solution_2 = $nums->last();