refactor: massive refactor to have only one binary to call
This commit is contained in:
72
README.md
72
README.md
@@ -16,26 +16,61 @@ Also, it's a fresh start from 2025. I do some exercises from other years along t
|
||||
## Repository Structure
|
||||
|
||||
```
|
||||
yyyy/
|
||||
├── dayXX/
|
||||
│ ├── main.go # The main code to run to print solutions.
|
||||
│ ├── main_test.go # The test file that validates the logic.
|
||||
│ └── input.txt # The day's puzzle input.
|
||||
└── ...
|
||||
├── cmd/
|
||||
│ └── aoc/
|
||||
│ └── main.go # CLI entry point that runs solutions
|
||||
└── internal/
|
||||
├── 2020/
|
||||
│ ├── DayOne/
|
||||
│ │ ├── code.go # Go solution for Day 1 (2020)
|
||||
│ │ └── code_test.go # Unit tests for Day 1
|
||||
│ └── ...
|
||||
├── 2021/
|
||||
│ └── ... # Additional years and days
|
||||
├── registry/
|
||||
│ └── registry.go # Central registry for day runners
|
||||
└── data/
|
||||
├── 2020/
|
||||
│ ├── DayOne/
|
||||
│ │ └── input.txt # Puzzle input for Day 1 (2020)
|
||||
│ └── ...
|
||||
└── ...
|
||||
```
|
||||
|
||||
Each day's code can be run with:
|
||||
Each day's solution is organized into its own folder, named according to the day number (e.g., `DayOne`, `DayTwo`). Inside each folder, you'll find a `code.go` file with the Go implementation of the solution and a `code_test.go` file containing corresponding tests. The input data for each puzzle is located in the `internal/data` directory, mirroring the code structure for easy access.
|
||||
|
||||
To connect each solution to the CLI, the repository uses a central registry located in `internal/registry/registry.go`. This registry is essentially a map linking a day key (combining year and day number) to assign a "day runner" which is a struct that specifies the `ParseInput`, `PartOne` and `PartTwo` functions of the day's problem.
|
||||
|
||||
When running a solution, the CLI (`cmd/aoc/main.go`) looks up the appropriate runner from the registry based on your command-line input, uses the parsing function to load the input data, and then runs the desired part (or both parts) using the registered solution functions.
|
||||
|
||||
## Usage
|
||||
|
||||
Build the CLI tool:
|
||||
|
||||
```bash
|
||||
cd yyyy/dayXX
|
||||
go run main.go
|
||||
make
|
||||
```
|
||||
|
||||
Expected output:
|
||||
Run a day's solution:
|
||||
|
||||
```bash
|
||||
Part 1: <answer>
|
||||
Part 2: <answer>
|
||||
bin/aoc 2020D1 # Run both parts
|
||||
bin/aoc 2020D1P1 # Run only part one
|
||||
bin/aoc 2020D1P2 # Run only part two
|
||||
```
|
||||
|
||||
Example output:
|
||||
|
||||
```bash
|
||||
$ bin/aoc 2020D1
|
||||
197451
|
||||
138233720
|
||||
|
||||
$ bin/aoc 2020D1P1
|
||||
197451
|
||||
|
||||
$ bin/aoc 2020D1P2
|
||||
138233720
|
||||
```
|
||||
|
||||
## Tests
|
||||
@@ -55,13 +90,18 @@ In this example, the calibration values of these four lines are 12, 38, 15, and
|
||||
Adding these together produces 142.
|
||||
```
|
||||
|
||||
I'm using these examples to validate my logic.
|
||||
I'm using these examples each day to validate my logic.
|
||||
|
||||
If you want to run those, you can use:
|
||||
Run all tests:
|
||||
|
||||
```bash
|
||||
cd dayXX
|
||||
go test
|
||||
make test
|
||||
```
|
||||
|
||||
Or run tests for a specific day:
|
||||
|
||||
```bash
|
||||
go test ./internal/2020/DayOne/...
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
Reference in New Issue
Block a user