2022 Day 5 Part 2
This commit is contained in:
parent
481285d925
commit
67ab12d6ba
1 changed files with 11 additions and 2 deletions
|
@ -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;
|
||||||
|
|
Loading…
Add table
Reference in a new issue