setName((string) static::$day) ->setDescription('Run day '.static::$day); } /** * Initializes the command after the input has been bound and before the input * is validated. */ protected function initialize(InputInterface $input, OutputInterface $output): void { $this->title = 'Advent of Code - Day '.static::$day; $dataFile = sprintf('%s/../data/day%d/data.txt', __DIR__, static::$day); $dataExampleFile = sprintf('%s/../data/day%d/example.txt', __DIR__, static::$day); if (file_exists($dataFile)) { $this->data = array_filter(explode(PHP_EOL, file_get_contents($dataFile))); } if (file_exists($dataExampleFile)) { $this->exampleData = array_filter(explode(PHP_EOL, file_get_contents($dataExampleFile))); } $output->writeln(''); $output->writeln($this->title); $output->writeln(str_repeat('-', strlen($this->title))); } /** * Executes the current command. * * @return int 0 if everything went fine, or an exit code */ protected function execute(InputInterface $input, OutputInterface $output): int { // Solve the examples if available. $resultPart1Example = 'n/a'; $resultPart2Example = 'n/a'; if ($this->exampleData) { $resultPart1Example = $this->part1($this->exampleData); $resultPart2Example = $this->part2($this->exampleData); } // Solve the real puzzle if available. $resultPart1 = 'n/a'; $resultPart2 = 'n/a'; if ($this->data) { $resultPart1 = $this->part1($this->data); $resultPart2 = $this->part2($this->data); } // Output all the results. $output->writeln('Part 1'); $output->writeln(sprintf('Example: %s', $resultPart1Example)); $output->writeln(sprintf('Result: %s', $resultPart1)); $output->writeln(str_repeat('-', strlen($this->title))); $output->writeln('Part 2'); $output->writeln(sprintf('Example: %s', $resultPart2Example)); $output->writeln(sprintf('Result: %s', $resultPart2)); return Command::SUCCESS; } /** * Solve the given data for part one of the puzzle. * * @param string[] $data The data to process. * * @return int|string The result or null if not (yet?) implemented. */ protected function part1(array $data): int|string { return 'n/a'; } /** * Solve the given data for part one of the puzzle. * * @param string[] $data The data to process. * * @return int|string The result or null if not (yet?) implemented. */ protected function part2(array $data): int|string { return 'n/a'; } }