Collection of task completed in AdventOfCode in various programming languages, such as JavaScript, Python, Rust etc.
- Complete 2024
- 2023 not imported yet (on the Mac I think)
- Complete tasks in more languages
- Implement commands for more languages
- TODO add rust (and JS?) checks in pre-commit hook
- TODO fix all file/folder paths in this document, relative to where they are supposed to be, like templates on line 44
- Bun for Javascript, install with:
powershell -c "irm bun.sh/install.ps1|iex" # https://bun.sh/docs/installation- Rust, install here: https://www.rust-lang.org/tools/install
These commands expects the script file to be named solution.* depending on the programming language (currently supported, Python and JavaScript), i.e. solution.js and solution.py. For Rust, go into the years folder, and the run cargo new dayX to create a new file, remove the main.rs file, and create bin/part1.rs and bin/part2.rs to start working.
The input files are expected to be named as:
test.txt- Test inputin.txt- Large input
In the templates folder there are templates for all used languages to get a start for creating the solutions.
After doing the information above the following commands can be run for various purposes, depending on the programming language:
aoc-load $1 $2- Tries to fetch the input data from the AdventOfCode website and write it toin.txt. Requires cookie token from website to be active and set.- Python
aot- Runssolution.pywithtest.txtas input (output in blue)aos- Runssolution.pywithin.txtas inputaoc- Runsaotandaos
- JavaScript
jaos- Runssolution.jswithtest.txtas input (output in blue)jaot- Runssolution.jswithin.txtas inputjaoc- Runsjaotandjaos
- Rust
raos <day> <part>- Runs<day>/bin/<part>.rswithtest.txtas input, where<day>and<part>is just the integer of the day, e.g.raos 7 1raot <day> <part>- Runsday<day>/bin/part<part>.rswithin.txtas input, where<day>and<part>is just the integer of the day, e.g.raos 7 1raoc <day> <part>- Runsraot <day> <part>andraos <day> <part>, where<day>and<part>is just the integer of the day, e.g.raos 7 1
# Add these to your ~/.bash_aliases
AOC="D:/workspace/AdventOfCode/2024" # change this to whatever your AOC directory is
AOC_COOKIE="" # get this from the cookies tab in network tools on the AOC website
alias aot="cd $AOC; echo -ne '\\e[0;34m'; python solution.py < test.txt; echo -ne '\\e[0m'"
alias aos="cd $AOC; python solution.py < in.txt"
alias aoc="aot; echo; aos"
alias jaos="cd $AOC; bun solution.js in.txt"
alias jaot="cd $AOC; bun solution.js test.txt"
alias jaoc="jaot; echo; jaos"
alias raos="rao in.txt"
alias raot="rao test.txt"
alias raoc="raoc_func"
function raoc_func() {
raot "$1" "$2" && echo && raos "$1" "$2"
}
function rao () {
prev_dir=$(pwd)
if [ $2 ]
then
cd $AOC
cd day$2
if [ $3 ]
then
cargo run --bin part$3 $AOC/$1
else
echo "Usage: rao <input_file> <day> <part>"
echo "Please provide which part to run"
fi
else
echo "Usage: rao <input_file> <day> <part>"
echo "Please provide which day to run"
fi
cd $prev_dir
}
function aoc-load () {
if [ $1 ]
then
curl --cookie "session=$AOC_COOKIE" https://adventofcode.com/$1/day/$2/input > in.txt
else
curl --cookie "session=$AOC_COOKIE" "$(echo `date +https://adventofcode.com/%Y/day/%d/input` | sed 's/\/0/\//g')" > in.txt
fi
}Then run e.g. exec bash or source /path/to/.bashrc to activate the changes.
There as several tools to make the formatting and linting of the project as automated as possible. Listed below is additional info regarding this.
To create and activate the virtual environment, install the requirements, run:
#python -m pip install --upgrade pip # Optional steps
#python -m pip install --upgrade virtualenv
python -m venv ./venv
source venv/bin/activate
source venv/Scripts/activate # Windows
pip install -r requirements.txt --upgrade
deactivate # To exit the environmentThis repository runs several scripts and checks before a commit can be created. Check .git-hooks for what is actually run.
To activate the git hooks locally run this command:
git config --local core.hooksPath .git-hooksThe requirements in requirements.txt is created by pip-compile command.
When you add a new package add it to requirements.in and then follow the instructions above in Virtual environment chapter and then run:
pip-compile --no-emit-index-url --output-file requirements.txt requirements.in