This repository provides starting code to get you set up for completing Advent of Code puzzles using JavaScript.
For comprehensive instructions, see Setting Up a Complete Project.
- Copy
template.js
. - Modify
function process(input) { }
in the newly copied file. - Save your puzzle input to a text file.
- Run your JavaScript file passing
-f
followed by the text file containing the puzzle input.
- Fork this reposity to your computer
- Create a folder named after the current year.
- This folder will be referred to as the
YEAR
directory in these instructions.
- Save your puzzle input (accessable from the Daily Puzzle page (sample) in a new file in a new folder called
YEAR/input
.
- It is recommended to name the file after the date. For example, for 2022 Day 01, save the puzzle input in
2022/input/01.txt
- You can save the puzzle input by pressing
Ctrl+S
on the input page (sample) or by creating a new text file and pasting in the input data.- Hint: if copying and pasting, be sure you are using UNIX ecoding for proper
\n
usage.
- Hint: if copying and pasting, be sure you are using UNIX ecoding for proper
- Copy
template.js
to a new file named after the date in the year directory.
- You will need to update the import statement from
require("./util/inputParser")
torequire("../util/inputParser")
- For example, for 2022 day 01, copy
template.js
to2022/01.js
- Write your solution code in
process(input)
. - Run to see the result with
node YEAR/JAVASCRIPT_FILE_NAME -f YEAR/input/DATA_FILE_NAME.txt
!
- For example, for 2022 day 01, run
node 2022/01 -f 2022/input/01.txt
. - Alternatively, hardcode the path to file in the
cliInput.load()
call for the file. For example,cliInput.load("2022/input/01.txt")
for 2022 day 01. - The output is what you will submit on the Advent of Code page.
Your final project structure will look like this:
project
β template.js
β ... (starting files)
β
ββββ2022
β 01.js
β ... (other solution files)
β
ββββinput
β 01.txt
β ... (other input files)
-f PATH/TO/FILE
: ParsesPATH/TO/FILE
's contents and intoinputParser.load()
's.then()
callback.-t "SAMPLE INPUT"
: Passes the string"SAMPLE INPUT"
intoinputParser.load()
's.then()
callback. Useful for debugging (you can use a smaller input to test functionality).-d
: Enable debug mode, which will output information about the data being processed