From 67ab12d6ba8c6ec77be8f5a33e076f23754a8347 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Mon, 5 Dec 2022 20:50:21 +0100 Subject: [PATCH] 2022 Day 5 Part 2 --- 2022/day5.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/2022/day5.php b/2022/day5.php index 2927911..feaf4a7 100644 --- a/2022/day5.php +++ b/2022/day5.php @@ -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); -$result = $mover->run($commands); -echo 'Top crates: ' . $result; \ No newline at end of file +echo 'Part 1: Top crates: ' . $mover->run($commands) . PHP_EOL; + +$mover = new CrateMover9001($stacks); +echo 'Part 2: Top crates: ' . $mover->run($commands) . PHP_EOL;