Answer ⏱ 80ms
Part 1 :
14902
Part 2 :
6489132
$solution_1 = 0;
foreach (set(range(0, 4))->permutations() as $sequence) {
$is = 0;
foreach ($sequence as $ps) {
$is = (new Intcode($input, [$ps, $is]))->run();
}
$solution_1 = max($is, $solution_1);
}
$solution_2 = 0;
foreach (set(range(5, 9))->permutations() as $sequence) {
$amb = set(range(0, 4))->map(fn ($i) => new Intcode($input, [array_values($sequence)[$i]]));
$amb[0]->input[] = 0;
while (true) {
foreach (range(0, 4) as $m) {
$amb[($m + 1) % 5]->input[] = $amb[$m]->run();
}
if ($amb[4]->ended) break;
}
$solution_2 = max($solution_2, $amb[4]->output->last());
}