2022 Day 5 Part 2

This commit is contained in:
Sven Weidauer 2022-12-05 20:50:21 +01:00
parent 481285d925
commit 67ab12d6ba

View file

@ -49,6 +49,15 @@ class CrateMover9000 extends CrateMover {
} }
} }
class CrateMover9001 extends CrateMover {
protected function move(int $count, string $from, string $to): void {
$moved = array_splice($this->stacks[$from], -$count);
$this->stacks[$to] = array_merge($this->stacks[$to], $moved);
}
}
$mover = new CrateMover9000($stacks); $mover = new CrateMover9000($stacks);
$result = $mover->run($commands); echo 'Part 1: Top crates: ' . $mover->run($commands) . PHP_EOL;
echo 'Top crates: ' . $result;
$mover = new CrateMover9001($stacks);
echo 'Part 2: Top crates: ' . $mover->run($commands) . PHP_EOL;