Starter template for solving Advent of Code in TypeScript.
- NPM setup so you can run a specific day or all days on the command line
- NPM setup so you can add a new day on the command line
- Timings for each part of each day
- Input for each day automatically exposed in
string
andstring[]
form - Testing setup with Jest included
- Solutions live in the src/days/ directory and extend the abstract class
Day
- These follow the naming convention
dayX.ts
(and the classes in codeDayX
)
- These follow the naming convention
- Inputs live in the inputs/ directory
- These follow the naming convention
dayX.txt
- These follow the naming convention
- Tests live in the test/ directory
- Test inputs live in the test-inputs/ directory and by default tests use these and not the real inputs
- This is so you can easily run tests against the smaller examples that are given for the AOC day
- If you want to run against the real input files, set the
USE_REAL_INPUTS
environment variable totrue
(example below)
- Run all days
npm start
- Run a single day
npm start -- 2
*
- Create a new day file
dayX.ts
in the src/days/ directory, exporting a classDayX
which extends the abstract classDay
- Create a new input file
dayX.txt
in the inputs/ directory - The easiest way to do this is to use the provided
add-day
script- e.g. Add files for Day 2
npm run add-day -- 2
*
- e.g. Add files for Day 2
- It is assumed all solutions will have two parts but share the same input
- Override the
partOne
andpartTwo
methods from theDay
abstract class and put your solutions there- You must return a value from these methods (typed as
unknown
so it can be anything)
- You must return a value from these methods (typed as
- Access input by using the
inputList
andinputString
variables that will be available in any subclass ofDay
- Run all tests
npm run test
- Run a single test
npm run test day1
- Run all tests on real input files
USE_REAL_INPUTS=true npm run test
- Create a new day test
dayX.spec.ts
file in the test/ directory (names don't actually matter like they do for solutions) - Create a new input file
dayX.txt
in the test-inputs/ directory as by default tests use these and not the real inputs- This is so you can easily run tests against the smaller examples that are given for the AOC day
- If you want to run against the real input files, set the
USE_REAL_INPUTS
environment variable totrue
* The --
is how to pass arguments to npm scripts - the commands above are passing the argument 2
.
- Day 1 solution class and input file are stubbed as a guide on how to extend the project, and how you can use the
inputList
andinputString
mentioned above - To get started simply replace
inputs/day1.txt
with the real input and the solutions insrc/day1.ts
with your own - A Day 1 test also exists at
test/day1.spec.ts
, mostly to show a few jest methods and how test input files can differ from actual ones. To get started with testing you can edit this class, and the input file attest-inputs/day1.txt