Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Advent of Code - All Years - Blazingly Fast

License

NotificationsYou must be signed in to change notification settings

MeanderingProgrammer/advent-of-code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

All Years - Blazingly Fast

Years Completed

Runtimes

Runtimes

History

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!

Input Data

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

Setup

Install Requirements

pip install -r scripts/requirements.txt

Set Aliases

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"

Build

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 NameAltDescriptionDefaultExample
language-lLimit build to the specified languagesNone-l rust
info-iOutputs which languages will be builtFalse-i

Run

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 NameAltDescriptionDefaultExample
template-tName that targets specific years / dayslatest-t languages
year-yList of years to runNone-y 2021 -y 2022
day-dList of days to runNone-d 1 -d 3 -d 5
language-lLimit runs to the specified languagesNone-l go
strategy-sA way to select which languages to runNone-s fastest
slow-SDefines the runtime (in ms) for slow100-S 500
test-TPasses test flag to each dayFalse-T
info-iOutputs which days would runFalse-i
  • Iftemplate is provided thenyear &day must not be provided
  • Ifyear orday are provided thentemplate must 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

Generate

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 NameAltDescriptionDefaultExample
template-tName that targets specific year / daynext-t next
year-yYear to generate starting files forNone-y 2022
day-dDay to generate starting files forNone-d 5
language-lLanguage to generate starting files forrust-l python
puzzle-pDownload puzzle description as wellFalse-p
info-iOutputs which day would get generatedFalse-i
  • Iftemplate is provided thenyear &day must not be provided
  • Ifyear orday are provided thentemplate must not be provided

Install aoc-cli

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

Graph

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 NameAltDescriptionDefaultExample
archive-aArchive existing graphsFalse-a
info-iOutputs whether graphs would be arhivedFalse-i

[8]ページ先頭

©2009-2025 Movatter.jp