Skip to main content

Helper utilities for solving Advent of Code puzzles

Project description

๐ŸŽ„ adventofcode PyPI - Version PyPI - Python Version

Screenshot 2025-12-02 at 10 04 42

Your framework for solving Advent Of Code puzzles ๐Ÿงฉ and benchmarking solutions ๐Ÿš€

  • Project scaffolding with uv run adventofcode init.
  • Assert and submit your solutions with uv run adventofcode run.
  • Benchmark all your solutions with uv run adventofcode benchmark.
  • No copy-pasting puzzle inputs or loading inputs from files.
  • Submit the answer immediately when your code returns the result. ๐Ÿ…

Table of Contents

Setup

uv init
uv add adventofcode
uv run adventofcode init

This will generate the scripts for each day:

.
โ”œโ”€โ”€ 01.py
โ”œโ”€โ”€ 02.py
โ”œโ”€โ”€ 03.py
โ”œโ”€โ”€ 04.py
โ”œโ”€โ”€ 05.py
โ”œโ”€โ”€ 06.py
โ”œโ”€โ”€ 07.py
โ”œโ”€โ”€ 08.py
โ”œโ”€โ”€ 09.py
โ”œโ”€โ”€ 10.py
โ”œโ”€โ”€ 11.py
โ”œโ”€โ”€ 12.py
โ”œโ”€โ”€ main.py
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ uv.lock

1 directory, 16 files

All the generated Python files look like this:

"""๐ŸŽ„ Solution for Day 1 of Advent of Code 2025 ๐ŸŽ„

Usage:

uv run adventofcode run 01.py
"""

inp = """your input"""
part1_asserts = [
    (inp, None),
]
part2_asserts = [
    (inp, None),
]


def part1(inp: str) -> str | int | None:
    return None


def part2(inp: str) -> str | int | None:
    return None

Session cookie

Before we can run these files we need to set up your session cookie. You can find the session cookie by going to [adventofcode.com] in your browser. Make sure you are logged in, then open your browser's developer tools and navigate to Application โ†’ Storage โ†’ Cookies. Look for the cookie named session and copy its value.

Then add the adventofcode.com session cookie value to your .env file:

# Set your Advent of Code session cookie below
# You can find it in your browser's developer tools after logging in to adventofcode.com.
# The name of the cookie is `session`.
AOC_SESSION="YOUR_SESSION_COOKIE_HERE"
AOC_YEAR=2025

or to your environment variables:

export AOC_SESSION="..."

Run and submit your solution

Implement your solution in part1 and part2 functions and run

uv run adventofcode run 01.py

This will:

  • Run your day 1, part1 function with the inputs provided in the part1_asserts iterable and compare them with the expected values. If the function's return value doesn't match the expected answer, the command will stop. Hint: Each puzzle usually contains example input and an expected answerโ€”these make for great asserts!
  • If all the part1_asserts pass, part1 will be called with your puzzle input fetched from adventofcode.com using your session cookie.
  • If part1 returns a non-None value for your puzzle input, that value will be submitted to adventofcode.com as your part 1 answer using your session cookie. All answer submissions are cached, so each unique answer will only be submitted once.
  • If your answer was correct the same process repeats for part2.

Benchmark all your solutions

You can benchmark your solutions with

uv run adventofcode benchmark

This will run each day's solution and parse the timing results from the output. The results will be printed to the console as well as added to your README.md.

If you are in a hurry you can also benchmark a single day's solution with

uv run adventofcode benchmark 05.py

Example console output:

Example README:

Day Status Part 1 Time Part 2 Time Total Time
01 โœ… 0.28ms ๐ŸŸข 0.41ms ๐ŸŸข 0.69ms ๐ŸŸข
02 โœ… 0.76ms ๐ŸŸข 1.13ms ๐ŸŸข 1.89ms ๐ŸŸข
03 โœ… 0.15ms ๐ŸŸข 0.33ms ๐ŸŸข 0.48ms ๐ŸŸข
04 โœ… 21.43ms ๐ŸŸข 4.79ms ๐ŸŸข 26.22ms ๐ŸŸข
05 โœ… 1.95ms ๐ŸŸข 3.51ms ๐ŸŸข 5.46ms ๐ŸŸข
06 โœ… 3.04ms ๐ŸŸข 3.91s ๐Ÿ”ด 3.91s ๐Ÿ”ด
07 โœ… 30.58ms ๐ŸŸข 1.01s ๐Ÿ”ด 1.04s ๐Ÿ”ด
08 โœ… 0.42ms ๐ŸŸข 0.60ms ๐ŸŸข 1.02ms ๐ŸŸข
09 โœ… 5.75ms ๐ŸŸข 1.01s ๐Ÿ”ด 1.02s ๐Ÿ”ด
10 โœ… 2.85ms ๐ŸŸข 3.05ms ๐ŸŸข 5.90ms ๐ŸŸข
11 โœ… 0.97ms ๐ŸŸข 37.60ms ๐ŸŸข 38.57ms ๐ŸŸข
12 โœ… 30.75ms ๐ŸŸข 31.96ms ๐ŸŸข 62.71ms ๐ŸŸข
13 โœ… 108.79ms ๐ŸŸก 342.44ms ๐ŸŸก 451.23ms ๐ŸŸก
14 โœ… 3.03ms ๐ŸŸข 380.22ms ๐ŸŸก 383.25ms ๐ŸŸก
15 โœ… 2.28ms ๐ŸŸข 4.71ms ๐ŸŸข 6.99ms ๐ŸŸข
16 โœ… 80.55ms ๐ŸŸข 124.54ms ๐ŸŸก 205.09ms ๐ŸŸก
17 โœ… 0.02ms ๐ŸŸข 19.99ms ๐ŸŸข 20.01ms ๐ŸŸข
18 โœ… 5.66ms ๐ŸŸข 6.98s ๐Ÿ”ด 6.99s ๐Ÿ”ด
19 โœ… 9.05ms ๐ŸŸข 99.83ms ๐ŸŸข 108.88ms ๐ŸŸก
20 โœ… 47.46s ๐Ÿ”ด 4.28s ๐Ÿ”ด 51.74s ๐Ÿ”ด
21 โœ… 0.22ms ๐ŸŸข 0.25ms ๐ŸŸข 0.47ms ๐ŸŸข
22 โœ… 603.65ms ๐ŸŸก 1.87s ๐Ÿ”ด 2.47s ๐Ÿ”ด
23 โœ… 223.80ms ๐ŸŸก 222.87ms ๐ŸŸก 446.67ms ๐ŸŸก
24 โš ๏ธ 0.94ms ๐ŸŸข - 0.94ms ๐ŸŸข
25 โœ… 6.02ms ๐ŸŸข - 6.02ms ๐ŸŸข
Total 48.60s ๐Ÿ”ด 20.34s ๐Ÿ”ด 68.94s ๐Ÿ”ด

Legend:

  • ๐ŸŸข < 100ms
  • ๐ŸŸก 100ms - 1s
  • ๐Ÿ”ด > 1s

Using AoC class

Alternatively, you can build your own workflow using the lower level AoC class

from adventofcode import AoC

aoc = AoC() # defaults to current year and parses the day from the filename (e.g. 01.py will be day 1)

aoc.print_p1() # prints the first part of the puzzle
inp = aoc.get_input() # returns the input as a string
# solve the puzzle here
...
aoc.submit_p1('part 1 answer') # submits the answer to the first part of the puzzle
aoc.print_p2() # prints the second part of the puzzle
# solve the puzzle here
...
aoc.submit_p2('part 2 answer') # submits the answer to the second part of the puzzle

Happy solving ๐ŸŽ„

Enjoy and have fun!

Similar projects

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

adventofcode-25.12.tar.gz (144.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

adventofcode-25.12-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file adventofcode-25.12.tar.gz.

File metadata

  • Download URL: adventofcode-25.12.tar.gz
  • Upload date:
  • Size: 144.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for adventofcode-25.12.tar.gz
Algorithm Hash digest
SHA256 384bf206c26b1210fd8686c7cd9de1cdf92c0614922def562132b1ce91523302
MD5 ecf37f6cc143009c2d2d38b804c4f512
BLAKE2b-256 539094f61ae24720ad744bc2e430697b0d894dbb05c191ee6b4c923a4585a954

See more details on using hashes here.

Provenance

The following attestation bundles were made for adventofcode-25.12.tar.gz:

Publisher: publish.yml on anze3db/adventofcode

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file adventofcode-25.12-py3-none-any.whl.

File metadata

  • Download URL: adventofcode-25.12-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for adventofcode-25.12-py3-none-any.whl
Algorithm Hash digest
SHA256 9c3aabb1a5c08bef0c325f4873be445057ab4aa4027a8aea031ec91d3cb1c87c
MD5 8fd263e085ecbc58cde0445f463fac58
BLAKE2b-256 4ecbe667359edee33d05220371b2572e152598c0f4d1ff1c7e44bbd54df27253

See more details on using hashes here.

Provenance

The following attestation bundles were made for adventofcode-25.12-py3-none-any.whl:

Publisher: publish.yml on anze3db/adventofcode

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page