I use Typescript on ubuntu 16.04.
- Install the depenencies with
npm install. - Get the puzzle inputs from year 2016 of advent of code for the desired days as
input.txtinto the proper folders. - Run the code with the start script, to get the solution.
Runnable scripts are defined in package.json.
| Type | Run | Description |
|---|---|---|
| Start | npm start ${folderName} |
runs the code with the data from input.txt in the selected folder. |
| Test | npm test ${folderName} |
runs the code with test inputs specified in test.ts file. |
| Lint | npm run lint | Check the codestyle. It is run before each commit, to ensure consistent style. |
| Diff | npm run diff ${day} |
Check the difference in my solution between the first and the second task code. Where day is the number of the day, padded to 2 characters. |
Where ${folderName} is in the form of ${day}_${task}, where day is padded to 2 characters and task can be 1 or 2. (E.g.: 02_1).
- You can copy the folders.
- The
input.txtusually does not change. index.tsis independent of the folder, do not need modification.- If you copy the first task folder in VSCode the folder name will automatically increase.
- E.g:
02_1-> copy -> paste ->02_2.
- E.g:
- The
solution.tshas to have afunction solution(input: string[]): stringfunction.
I debug my code with VSCode. I've added launch configs to achieve that easily and repeatable.
- Add a breakpoint to
checkResultfunction intest.tsfile in the actual${day}_${task}folder. - Add the desired breakpoints.
- Step into any file in that folder when you lauch:
Run tests for current day. - Now you can check data in
Debug menuand try out code inDebug console.
If you'd like to debug with custom data, feel free to add that data as the first test, into test.ts file into the testdata array (usually data) in the form of {input: string[], expected: string}.
- Get the
input.txtfile for the selected folder, if you haven't yet done so. - Add a breakpoint to
evaluateInputfunction inindex.tsfile in the actual${day}_${task}folder. - Add the desired breakpoints.
- Step into any file in that folder when you lauch:
Debug on input. - Now you can check data in
Debug menuand try out code inDebug console.
You need to reset the debug session after the first run to stop on breakpoints with VSCode.
Don't forget to add a breakpoint in
test.ts/index.tsto make sure it stops there.
Solution: use "protocol": "inspector" on windows in launch config.