Skip to content

My collection of Advent of Code solutions in a slightly overkill project setup 🙃👻

License

Notifications You must be signed in to change notification settings

Alexdruso/adventofcode

Repository files navigation

Advent of Code ⭐️

Stars collectedcodecovtestsversion

advent of codeadvent of code

Collection of my Advent of Code solutions in an overkill project setup 👻🎄.

Features ✨

  • Solutions are timed with the help of a decorator using time.perf_counter
  • Solution and time are printed to console using the rich package with truecolor
  • Solution profiler decorator using Cprofile and pstats
  • Automatic listing of completed solutions in the README
  • Automatic changelog, using semantic versioning and the conventional commit specification
  • A badge that is updated automatically with the amount of stars I've collected
  • A svg image that is updated automatically with the amount of stars in the style of Advent of Code
    • Has a dark mode and light mode version which are visible only when their respective mode is used by the user
    • Has an animated star emoji which helps the Elves save Christmas
  • Pip installable (pip install -e .) with:
    • A generate-readme script, which updates the readme
    • A generate-benchmarks script, which runs all solutions and saves the duration of each solution to these tables
    • A run-all script, which dynamically calls every solution in every adventofcode.year_*.day_* module
    • An add-day script, which add a solution day file using a template and downloads the input data from the AOC site automatically
  • Type checked (mypy) and linted (flake8)
  • Tested against multiple python versions on each push to master and pull request

Completed ⭐️

2015

Solutions for 2015

daypart onepart two
01⭐️⭐️
02⭐️⭐️
03⭐️⭐️
04⭐️⭐️
05⭐️⭐️
06⭐️⭐️
07⭐️⭐️
08⭐️⭐️
09⭐️⭐️
10⭐️⭐️
11⭐️⭐️
12⭐️⭐️
13⭐️⭐️
14⭐️⭐️
15⭐️⭐️
16⭐️⭐️
17⭐️⭐️
18⭐️⭐️
19⭐️⭐️
20⭐️⭐️
21⭐️⭐️
22⭐️⭐️
23⭐️⭐️
24⭐️⭐️
25⭐️⭐️

2020

Solutions for 2020

daypart onepart two
01⭐️⭐️
02⭐️⭐️
03⭐️⭐️
04⭐️⭐️
05⭐️⭐️
06⭐️⭐️
07⭐️⭐️
08⭐️⭐️
09⭐️⭐️
10⭐️⭐️
11⭐️⭐️
12⭐️⭐️
13⭐️⭐️
14⭐️⭐️
15⭐️⭐️
16⭐️⭐️

2021

Solutions for 2021

daypart onepart two
01⭐️⭐️
02⭐️⭐️
03⭐️⭐️
04⭐️⭐️
05⭐️⭐️
06⭐️⭐️
07⭐️⭐️
08⭐️⭐️
09⭐️⭐️
10⭐️⭐️
11⭐️⭐️
12⭐️⭐️
13⭐️⭐️
14⭐️⭐️
15⭐️⭐️
16⭐️⭐️
17⭐️⭐️
18⭐️⭐️
19⭐️⭐️
20⭐️⭐️
21⭐️⭐️
22⭐️⭐️
25⭐️-

2022

Solutions for 2022

daypart onepart two
01⭐️⭐️
02⭐️⭐️
03⭐️⭐️
04⭐️⭐️
05⭐️⭐️
06⭐️⭐️
07⭐️⭐️
08⭐️⭐️
09⭐️⭐️
10⭐️⭐️
11⭐️⭐️
13⭐️⭐️
14⭐️⭐️
15⭐️⭐️

2023

Solutions for 2023

daypart onepart two
01⭐️⭐️
02⭐️⭐️
03⭐️⭐️
04⭐️⭐️
05⭐️⭐️
06⭐️⭐️
07⭐️⭐️
08⭐️⭐️
09⭐️⭐️

2024

Solutions for 2024

daypart onepart two
01⭐️⭐️

2025

Solutions for 2025

daypart onepart two
01⭐️⭐️

Benchmarks 🚀

2015

Benchmarks for 2015

daypartduration

2020

Benchmarks for 2020

daypartduration

2021

Benchmarks for 2021

daypartduration

2022

Benchmarks for 2022

daypartduration
01part one0.59 ms
01part two0.61 ms
02part one2.24 ms
02part two2.55 ms
02part one with mapping0.15 ms
02part two with mapping0.14 ms
03part one0.71 ms
03part two0.74 ms
04part one1.62 ms
04part two5.18 ms
05part one1.66 ms
05part two1.04 ms
06part one0.49 ms
06part two3.66 ms
07part one21.97 ms
07part two18.47 ms
08part one229.68 ms
08part two80.63 ms
09part one15.73 ms
09part two38.07 ms

2023

Benchmarks for 2023

daypartduration
01part one1.00 ms
01part two4.73 ms
02part one1.49 ms
02part two1.67 ms
03part one3.92 ms
03part two3.99 ms
04part one5.46 ms
04part two6.52 ms
05part one9.85 ms
05part two418.57 ms
06part one0.15 ms
06part two17472.53 ms
06part two quadratic0.03 ms
07part one38.53 ms
07part two75.51 ms
08part one2.98 ms
08part two34.70 ms
09part one4.44 ms
09part two4.88 ms

2024

Benchmarks for 2024

daypartduration

2025

Benchmarks for 2025

daypartduration

Decorators

What's Christmas without decorations? 🎄

Solution timer

The solution timer times the solution using time.perf_counter and outputs the answer and the duration to the console

Example:

@register_solution(2015, 9, 1) # year, day, partdefpart_one(input_data: list[str]) ->int: ...

Output:

2015 day 09 part 01: 251 in 0.1356 ms 

Solution profiler

The solution profiler runs the cProfiler against the solution and outputs the profiler stats using pstats to the console. It takes an optional amount kwarg to set the amount of stats to display, and an optional sort kwarg to set the sorting to either time or cumulative.

Example:

@solution_profiler(2015, 9, 1) # year, day, partdefpart_one(input_data: list[str]) ->int: ...

Output:

91416 function calls (90941 primitive calls) in 0.159 seconds Ordered by: internal time List reduced from 217 to 3 due to restriction <10> ncalls tottime percall cumtime percall filename:lineno(function) 1 0.133 0.133 0.136 0.136 /Users/marcelblijleven/.../day_09_2015.py:39(_get_route_distances) 1 0.012 0.012 0.015 0.015 /Users/marcelblijleven/.../day_09_2015.py:30(get_all_routes) 82182 0.006 0.000 0.006 0.000{method 'append' of 'list' objects} 

Scripts

add-day

The add-day script creates a file based on a 'solution day' template into the correct year module. If no input is found for that day, it will automatically download the input and save it in the inputs directory. Note: this only works if the session cookie is stored in .session. To get this value:

  1. Go to the AOC site.
  2. Make sure you're logged in, every user has unique input data
  3. View the cookies and copy the value of the session cookie.
  4. Paste the cookie value into the .session file

Example:

(venv) add-day 2015 14

Output:

(venv) [adventofcode] add-day 2015 14 master ✗ ✭ ✱ Creating solution day file for year 2015 day 14 Wrote template to /Users/marcelblijleven/code/github.com/marcelblijleven/adventofcode/src/adventofcode/year_2015/day_14_2015.py Input data already exists for year 2015 day 14, skipping download 

generate-readme

The generate-readme script dynamically searches for all solutions and writes them to the README.md file. When a solution file has a function called part_one, it adds a star. When it has a function called part_two, it adds another star. The star counter badge at the top of the README.md file is then updated with the total amount of stars found.

This script is only used in the Github workflow update_readme.yml, but can be run locally to using generate-readme

clean-repo

The clean-repo script is used to delete all solutions and inputs from the project. This can be useful if you want to start over, or if you've just forked this repo. The clean-repo command is run in 'dry run mode' by default, to disable it and actually start deleting directories and files, use:

(venv) clean-repo --dry-run false

Note: not all years/solutions have been migrated yet from my previous repositories

About

My collection of Advent of Code solutions in a slightly overkill project setup 🙃👻

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python99.7%
  • Makefile0.3%