Refactor framework to support more years

This commit is contained in:
2021-12-09 22:41:22 +01:00
parent d3cd95aed2
commit 9891975d0f
56 changed files with 1257 additions and 1084 deletions

View File

@ -1,4 +1,4 @@
# Advent of Code 2021
# Advent of Code
In this repository, you'll find my solutions.
@ -6,17 +6,17 @@ In this repository, you'll find my solutions.
## 🛠 Setup and running
- Run `composer install` to install the dependencies.
- Run `./aoc21 {day}` to run the solution for a specific day (for example `./aoc21 1` to run the code for day 1)
- Run `./aoc21 puzzle {day}` to get the description of the puzzle for the specific day.
- Run `./aoc {day} {year?}` to run the solution for a specific day. If year is not given, use the current year (for example `./aoc 1` to run the code for day 1 2021)
- Run `./aoc21 puzzle {day} {year?}` to get the description of the puzzle for the specific day.
- Run `composer test` to automatically validate the solutions.
## 🧩 Add a new puzzle/solution
- Create a directory in `./data` with the correct name.
- Create a directory in `./data/Y??/day?` with the correct name.
- Create `example.txt` with the example values from the puzzle.
- Create `data.txt` with your personal input.
- Create `puzzle.md` with the puzzle. You can use [this plugin](https://github.com/kfarnung/aoc-to-markdown) to easily convert the puzzle to markdown.
- Create a new class in the `src` directory and make sure it has the structure defined below.
- Add this class to the `./aoc21` file, and you can run it.
- Create a new class in the `src/Y??/` directory and make sure it has the structure defined below.
- Add this class to the `./aoc` file, and you can run it.
- Add a new test in `./tests` with structure defined below.
- Run `composer test` to run all the tests.
@ -26,14 +26,19 @@ In this repository, you'll find my solutions.
```php
<?php
namespace AdventOfCode21;
namespace trizz\AdventOfCode\Y21;
// Make sure the classname is correct.
class Day1 extends AbstractCommand
class Day1 extends Solution
{
// Update this to the day number.
protected static int $day = 1;
// Provide the expected results for part 1.
public static int $part1ExampleResult = null;
public static int $part1Result = null;
// Provide the expected results for part 2.
public static int $part2ExampleResult = null;
public static int $part2Result = null;
protected function part1(array $data): int
{
// Solution for part 1.
@ -47,34 +52,3 @@ class Day1 extends AbstractCommand
```
</details>
<details>
<summary>Solution test structure</summary>
```php
<?php
namespace Tests;
// Make sure the classname is correct.
class Day1Test extends AbstractTestCase
{
// Provide the expected results for part 1.
public static int $part1ExampleResult = 7;
public static int $part1Result = 1688;
// Provide the expected results for part 2.
public static int $part2ExampleResult = 5;
public static int $part2Result = 1728;
// Make a new instance of the command with the 'ReturnTestableResults' trait.
public function setupDay(): Day1
{
return new class() extends Day1 {
use ReturnTestableResults;
};
}
}
```
</details>