My solutions for the Advent of Code in NodeJS
Each day consists of two puzzles.
I added a README.md file to each Day, which contains the instructions exactly as they were displayed on https://adventofcode.com/
- Open up your favourite terminal (and navigate somewhere you want to download the repository to).
- Make sure you have NodeJS installed. Test by entering
$node -v
If this returns a version number, NodeJS is installed. If not, get NodeJS here. - Clone the repository and navigate to it.
$git clone https://github.com/NullDev/Advent-of-Code.git && cd Advent-of-Code
- Check out the template branch in your fork from my remote. (IF YOU SEE THIS: YOU ARE ON THE CORRECT BRANCH)
$git checkout -b template origin/template
- Push your newly created branch and make sure to set it as your default branch on GitHub (
REPO/settings/branches
). - Install all dependencies by typing
$npm install
- Remove all years that weren't made by you (if all:
rm -r "./20*"
) and maybe alter the README - Copy
config.template.json
and paste it asconfig.json
- Go to https://adventofcode.com/ and login with your account. Then copy the value from the
session
cookie and paste it into theconfig.json
file (See here if you don't know how). - (OPTIONAL) If you wish to use the GitHub Action for the "Prepare Day automatically at 0:10 workflow" you need to go to your repository settings -> secrets -> actions and add
SESSION_COOKIE
with your session string.
- To automatically setup and prepare the current day, simply type
npm run prepare-today
- If you finished part one and want to get the readme updated, simple run the command again.
- Optionally, to prepare a previous day, type
node prepare_day.js YEAR-DAY
- Example:node prepare_day.js 2020-12
Both of those commands will create a folder for the day/year, fetch the task from the website & convert it to a README.md, fetch the input and create template files for the solution.
Each script can be run stand-alone / separatly but I've also created a start_all.js
script to launch all days in order, and display the solutions along with an approximated benchmark (the benchmark uses performance.now()
to measure the execution time and does not include the actual reading of the file except when the file is read line-by-line).
- Run all years:
npm run start:all
- Run a specific year:
npm run start:YEAR
- Example:npm run start:2020
- Run a specific year and day:
npm run start:YEAR DAY
- Example:npm run start:2020 3
- Run todays parts:
npm run start:today
- Run a specific day & part:
node YEAR/DAY/part_[1 OR 2].js
- Example:node 2020/01/part_2.js
- All Puzzles & Inputs (
Day_XX/README.md
's andDay_XX/input.txt
's) Copyright (c) Eric Wastl (@ericwastl) - All Puzzle Solutions1 (
Day_XX/part_1.js
's andDay_XX/part_2.js
's) Copyright (c) <your name> (<your link>)
Footnotes
-
Unless otherwise noted in the Code ↩