diff --git a/src/ExecuteDay.php b/src/ExecuteDay.php index 33ff7e5..2857834 100644 --- a/src/ExecuteDay.php +++ b/src/ExecuteDay.php @@ -9,15 +9,14 @@ use Symfony\Component\Console\Output\OutputInterface; class ExecuteDay extends Command { + protected int $day; + + protected int $year; /** * @var string The title. */ private string $title; - protected int $day; - - protected int $year; - /** * Configure the command. */ diff --git a/src/Puzzle.php b/src/Puzzle.php index 8b9a588..3b53956 100644 --- a/src/Puzzle.php +++ b/src/Puzzle.php @@ -2,11 +2,11 @@ namespace trizz\AdventOfCode; -use trizz\AdventOfCode\Utils\SymfonyConsoleMarkdown; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use trizz\AdventOfCode\Utils\SymfonyConsoleMarkdown; class Puzzle extends Command { diff --git a/src/Solution.php b/src/Solution.php index 30cb06a..94f606c 100644 --- a/src/Solution.php +++ b/src/Solution.php @@ -3,9 +3,6 @@ namespace trizz\AdventOfCode; use JetBrains\PhpStorm\ArrayShape; -use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; abstract class Solution { @@ -93,7 +90,7 @@ abstract class Solution return !empty($this->exampleData); } - #[ArrayShape(['part1' => "int|string", 'part2' => "int|string"])] + #[ArrayShape(['part1' => 'int|string', 'part2' => 'int|string'])] public function results(bool $useExampleData = true): array { $data = $useExampleData ? $this->exampleData : $this->data; diff --git a/src/Utils/Str.php b/src/Utils/Str.php index 3cf7ed3..7e573cf 100644 --- a/src/Utils/Str.php +++ b/src/Utils/Str.php @@ -11,7 +11,7 @@ class Str */ public static function matchesAll(string $one, string $two): bool { - for ($index = 0, $length = strlen($two); $index < $length; $index++) { + for ($index = 0, $length = strlen($two); $index < $length; ++$index) { if (!str_contains($one, $two[$index])) { return false; } diff --git a/src/Y21/Day4.php b/src/Y21/Day4.php index 701ad73..9b05c7d 100644 --- a/src/Y21/Day4.php +++ b/src/Y21/Day4.php @@ -12,6 +12,22 @@ class Day4 extends Solution public static int|string|null $part2ExampleResult = 1924; public static int|string|null $part2Result = 17435; + /** + * {@inheritdoc} + */ + public function part1(array $data): int|string + { + return $this->playBingo($data, firstWins: true); + } + + /** + * {@inheritdoc} + */ + public function part2(array $data): int|string + { + return $this->playBingo($data, firstWins: false); + } + /** * @param int[] $winningCard * @param int $number @@ -30,22 +46,6 @@ class Day4 extends Solution return (int) array_sum($unusedNumbers) * $number; } - /** - * {@inheritdoc} - */ - public function part1(array $data): int|string - { - return $this->playBingo($data, firstWins: true); - } - - /** - * {@inheritdoc} - */ - public function part2(array $data): int|string - { - return $this->playBingo($data, firstWins: false); - } - /** * @param string $numberList * @param string $separator diff --git a/src/Y21/Day6.php b/src/Y21/Day6.php index b582787..2309e86 100644 --- a/src/Y21/Day6.php +++ b/src/Y21/Day6.php @@ -2,8 +2,8 @@ namespace trizz\AdventOfCode\Y21; -use trizz\AdventOfCode\Solution; use JetBrains\PhpStorm\Immutable; +use trizz\AdventOfCode\Solution; class Day6 extends Solution { diff --git a/src/Y21/Day8.php b/src/Y21/Day8.php index 90cc79c..c703484 100644 --- a/src/Y21/Day8.php +++ b/src/Y21/Day8.php @@ -38,7 +38,7 @@ class Day8 extends Solution ) ); - return (count(array_intersect($values, [2, 4, 3, 7]))); + return count(array_intersect($values, [2, 4, 3, 7])); } public function part2(array $data): int|string @@ -89,26 +89,26 @@ class Day8 extends Solution 8 => static fn (string $pattern) => strlen($pattern) === 7, // 9 is 6 segments, matches segments for 4 9 => fn (string $pattern) => strlen($pattern) === 6 && Str::matchesAll( - $pattern, - $this->digitPatterns[4] ?? '' - ), + $pattern, + $this->digitPatterns[4] ?? '' + ), // 0 is 6 segments, matching 1's segments (9 is already out) 0 => fn (string $pattern) => strlen($pattern) === 6 && Str::matchesAll( - $pattern, - $this->digitPatterns[1] ?? '' - ), + $pattern, + $this->digitPatterns[1] ?? '' + ), // 6 is 6 segments, the only one left 6 => static fn (string $pattern) => strlen($pattern) === 6, // 3 is 5 segments and matches 1's segments 3 => fn (string $pattern) => strlen($pattern) === 5 && Str::matchesAll( - $pattern, - $this->digitPatterns[1] ?? '' - ), + $pattern, + $this->digitPatterns[1] ?? '' + ), // 5 is 5 segments, and 9 has all the segments of 5 5 => fn (string $pattern) => strlen($pattern) === 5 && Str::matchesAll( - $this->digitPatterns[9] ?? '', - $pattern - ), + $this->digitPatterns[9] ?? '', + $pattern + ), // 2 is the only one remaining 2 => static fn (string $pattern) => true, ]; @@ -122,6 +122,7 @@ class Day8 extends Solution unset($patterns[$key]); $this->patternDigits[$pattern] = $digit; $this->digitPatterns[$digit] = $pattern; + break; } }