- Notifications
You must be signed in to change notification settings - Fork2
Advent of Code - All Years - Blazingly Fast
License
MeanderingProgrammer/advent-of-code
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
All Years - Blazingly Fast
When I first started Advent in 2020 I wrote everything inPython for simplicityas well as getting better at my main scripting language.
I then decided to go back and solve all the years from 2015 on also inPython.
Since then I have used Advent as an opportunity to learn new languages.
So far this has been:
Sometime after 2022 I decided to go back and optimize every solution with the goalof having no single solution take more than 1 second to run. Sometimes this involvesalgorithm improvements, other times I decided to re-write solutions fromPythoninto something likeRust orGo. Currently the slowest solution takes just under250 ms, so mission accomplished. Now the total runtime is such that each year takesless than 1 second!
The input for each puzzle is in a separate private Github repo
This is done to comply with the policyhere.
These inputs end up in thedata folder in the same structure as the solutions.
For instance the input for year2020 day5 is filedata/2020/05/data.txt.
After cloning this repo the following command needs to be run to get the data.
git submodule update --init
This also means when pulling changes theupdate command must also be ran.
git submodule update
pip install -r scripts/requirements.txt
alias a-build="./scripts/advent.py build"alias a-run="./scripts/advent.py run"alias a-gen="./scripts/advent.py generate"alias a-graph="./scripts/advent.py graph"
Thebuild target is used to do any language specific setup prior to running.
This includes downloading any necessary libraries, compiling targets, etc.
None of the parameters are required, the default behavior in this case is tobuild and test all supported languages.
- Alias Command:
a-build - Direct Command:
./scripts/advent.py build
Usage
a-build \ (--language<language>)* \ --info?
| Variable Name | Alt | Description | Default | Example |
|---|---|---|---|---|
| language | -l | Limit build to the specified languages | None | -l rust |
| info | -i | Outputs which languages will be built | False | -i |
Therun target is used to run various days rather than running directly.
Does some hacky stuff to set arguments and run commands, but for the most part runsstandard build commands for each language / framework.
None of the parameters are required, the default behavior in this case is to runthe latest day in the fastest language it is implemented in.
- Alias Command:
a-run - Direct Command:
./scripts/advent.py run
Usage
a-run \ --template<template>? \ (--year<year>)* \ (--day<day>)* \ (--language<language>)* \ --strategy<strategy>? \ --slow<time>? \ --test? \ --info?
| Variable Name | Alt | Description | Default | Example |
|---|---|---|---|---|
| template | -t | Name that targets specific years / days | latest | -t languages |
| year | -y | List of years to run | None | -y 2021 -y 2022 |
| day | -d | List of days to run | None | -d 1 -d 3 -d 5 |
| language | -l | Limit runs to the specified languages | None | -l go |
| strategy | -s | A way to select which languages to run | None | -s fastest |
| slow | -S | Defines the runtime (in ms) for slow | 100 | -S 500 |
| test | -T | Passes test flag to each day | False | -T |
| info | -i | Outputs which days would run | False | -i |
- If
templateis provided thenyear&daymust not be provided - If
yearordayare provided thentemplatemust not be provided
Process Runtime Output
cat all.json| jq -r'.[]|[.year, .day, .language, .runtime]|@tsv'cat all.json| jq -r'.[]|[.year, .day, .language, .runtime]|@tsv'| sort -nk4cat all.json| jq -r'.[]|[.year, .day, .language, .runtime]|@tsv'| sort -nk4| awk'{ if ($4 > 100) { print $0 } }'cat all.json| jq -r'.[]|select(.year == 2015 and .day == 24)'cat all.json| jq -r'.[]|.runtime'| awk'{ sum+=$1 } END { print sum, "ms" }'cat all.json| jq -r'.[]|select(.year == 2015)|.runtime'| awk'{ sum+=$1 } END { print sum, "ms" }'cat all.json| jq -r'.[]|[.year, .runtime]|@tsv'| awk'{ years[$1] += $2 } END { for (year in years) { print year, years[year], "ms" } }'
Unit Test
This will test that some shared logic works across usage days. Such as theint-codeimplementation from 2019.
pytest -s scripts
Thegenerate target creates initial files and empty data file for the specifiedlanguage.
Will do any other required setup, such as updatingCargo.toml forrust.
Will pull down your puzzle input ifinstructions are followed.
None of the parameters are required, the default behavior in this case is to generatethe next day using the rust template.
- Alias Command:
a-gen - Direct Command:
./scripts/advent.py generate
Usage
a-gen \ --template<template>? \ --year<year>? \ --day<day>? \ --language<language>? \ --puzzle? \ --info?
| Variable Name | Alt | Description | Default | Example |
|---|---|---|---|---|
| template | -t | Name that targets specific year / day | next | -t next |
| year | -y | Year to generate starting files for | None | -y 2022 |
| day | -d | Day to generate starting files for | None | -d 5 |
| language | -l | Language to generate starting files for | rust | -l python |
| puzzle | -p | Download puzzle description as well | False | -p |
| info | -i | Outputs which day would get generated | False | -i |
- If
templateis provided thenyear&daymust not be provided - If
yearordayare provided thentemplatemust not be provided
Template generation script can useaoc-cli to download input:docs.
Follow the instructions in theREADME ofaoc-cli to get your session cookie setup.
This library relies on openssl which you will also need to install if you don't alreadyhave it.
cargo install aoc-clitouch .adventofcode.session
Thegraph target creates a variety of graphs to visualize the runtime of days splitand grouped on different dimensions.
None of the parameters are required, the default behavior in this case is to createonly new graphs and skip graphs that have been created before.
- Alias Command:
a-graph - Direct Command:
./scripts/advent.py graph
Usage
a-graph \ --archive? \ --info?
| Variable Name | Alt | Description | Default | Example |
|---|---|---|---|---|
| archive | -a | Archive existing graphs | False | -a |
| info | -i | Outputs whether graphs would be arhived | False | -i |
About
Advent of Code - All Years - Blazingly Fast
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.

