My solutions for Advent of Code, written in TypeScript.
This project uses pnpm for dependency management.
pnpm install.
├── src/
│ ├── day01/
│ │ ├── solution.ts
│ │ ├── solution.test.ts
│ │ ├── README.md
│ │ ├── input1.txt (not tracked in git)
│ │ ├── input2.txt (not tracked in git)
│ │ ├── expectation1.txt (not tracked in git)
│ │ └── expectation2.txt (not tracked in git)
│ ├── day02/
│ │ ├── solution.ts
│ │ ├── solution.test.ts
│ │ ├── README.md
│ │ ├── input1.txt (not tracked in git)
│ │ ├── input2.txt (not tracked in git)
│ │ ├── expectation1.txt (not tracked in git)
│ │ └── expectation2.txt (not tracked in git)
│ └── ...
└── ...
To add a new day, use the generate-day script:
pnpm generate-day <dayNumber>For example, to generate day 2:
pnpm generate-day 2This will create a new folder src/day02/ with:
solution.ts- Template for your solution functions (part1andpart2)solution.test.ts- Test file templateREADME.md- Empty file where you can paste the problem descriptions for part 1 and part 2input1.txt- Empty file for part 1 input (not tracked in git)input2.txt- Empty file for part 2 input (not tracked in git)expectation1.txt- Empty file for part 1 expectation (not tracked in git)expectation2.txt- Empty file for part 2 expectation (not tracked in git)
After generating a day, you can:
- Paste the problem descriptions into
README.md. - Add your input data to
input1.txtandinput2.txt. - Implement your solution in
solution.ts. - Update the expected values in
expectation1.txtandexpectation2.txt. - Run the tests with
pnpm testto see if your solution is correct.
pnpm generate-day <dayNumber>- Generate a new day folder with template files (e.g.,pnpm generate-day 2)pnpm test- Run tests with Vitestpnpm test:watch- Run tests in watch modepnpm lint- Lint code with Oxlintpnpm format- Format code with Prettierpnpm format:check- Check code formatting
This repository includes a GitHub Actions workflow (.github/workflows/check.yaml) that automatically runs on pull requests and pushes to the main branch. The workflow:
- Runs the linter (
pnpm lint) - Checks code formatting (
pnpm format:check) - Validates that test files have not been changed to contain hardcoded answers
To enforce that all checks pass before merging pull requests:
- Go to your repository Settings
- Navigate to Rules → Rulesets
- Click New ruleset → New branch ruleset
- Configure the ruleset name and target branches (e.g.,
main) - Enable Require status checks to pass
- Click Show additional settings
- Under Status checks that are required, click Add checks
- Type
checkand select the check action - Click Save changes
- Input files (
input*.txt) - Expectation files (
expectation*.txt)
Why do we exclude these files from git?
AoC is all about the mystery about problems, inputs, and the final answers. Since I don't want to give away the answers, I want to keep the mystery alive.