Skip to content

NullDev/Advent-of-Code

Repository files navigation

🎄 Advent-of-Code

My solutions for the Advent of Code in NodeJS


ℹ️ About Advent of Code

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/


💡 How to use this repository

🔧 Initial Setup

  1. Open up your favourite terminal (and navigate somewhere you want to download the repository to).

  2. 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.

  3. Clone the repository and navigate to it.
    $ git clone https://github.com/NullDev/Advent-of-Code.git && cd Advent-of-Code

  4. Check out the template branch in your fork from my remote. (IF YOU SEE THIS: YOU ARE ON THE WRONG BRANCH)
    $ git checkout -b template origin/template

  5. Push your newly created branch and make sure to set it as your default branch on GitHub (REPO/settings/branches).

  6. Install all dependencies by typing
    $ npm install

  7. Remove all years that weren't made by you (if all: rm -r "./20*") and maybe alter the README

  8. Copy config.template.json and paste it as config.json

  9. Go to https://adventofcode.com/ and login with your account. Then copy the value from the session cookie and paste it into the config.json file (See here if you don't know how).

  10. (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.

☀️ Starting a new day

  • 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.

🚀 Running benchmarks

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

📜 License

  • All Puzzles & Inputs (Day_XX/README.md's and Day_XX/input.txt's) Copyright (c) Eric Wastl (@ericwastl)
  • All Puzzle Solutions1 (Day_XX/part_1.js's and Day_XX/part_2.js's) Copyright (c) NullDev (nulldev.org)

🏆 Goal

I attempted to solve every problem as functional as possible and with as little code as possible while still being performant.
Some solutions could be one-liners but I left them splitted up for the sake of readability.

I also tried to experiment with a couple of different things:

2019:

2020:

2021:

2022

2023


🚀 Benchmarks Preview


⭐ Yay

image


Footnotes

  1. Unless otherwise noted in the Code