adventofcode 26.1__tar.gz → 26.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- adventofcode-26.2/PKG-INFO +254 -0
- adventofcode-26.2/README.md +223 -0
- {adventofcode-26.1 → adventofcode-26.2}/pyproject.toml +2 -1
- {adventofcode-26.1 → adventofcode-26.2}/pyproject.toml.orig +2 -2
- adventofcode-26.2/src/adventofcode/__init__.py +380 -0
- adventofcode-26.2/src/adventofcode/auth.py +45 -0
- adventofcode-26.2/src/adventofcode/benchmark.py +495 -0
- adventofcode-26.2/src/adventofcode/cli.py +361 -0
- adventofcode-26.2/src/adventofcode/puzzle.py +159 -0
- adventofcode-26.2/src/adventofcode/utils.py +49 -0
- adventofcode-26.1/PKG-INFO +0 -239
- adventofcode-26.1/README.md +0 -208
- adventofcode-26.1/src/adventofcode/__init__.py +0 -194
- adventofcode-26.1/src/adventofcode/cli.py +0 -758
- adventofcode-26.1/src/adventofcode/utils.py +0 -10
- {adventofcode-26.1 → adventofcode-26.2}/src/adventofcode/__about__.py +0 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: adventofcode
|
|
3
|
+
Version: 26.2
|
|
4
|
+
Summary: Helper utilities for solving Advent of Code puzzles
|
|
5
|
+
Keywords:
|
|
6
|
+
Author: Anže Pečar
|
|
7
|
+
Author-email: Anže Pečar <anze@pecar.me>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Programming Language :: Python
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
16
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
17
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
18
|
+
Requires-Dist: requests
|
|
19
|
+
Requires-Dist: percache
|
|
20
|
+
Requires-Dist: beautifulsoup4
|
|
21
|
+
Requires-Dist: python-dotenv
|
|
22
|
+
Requires-Dist: rich
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Project-URL: Documentation, https://github.com/anze3db/adventofcode#readme
|
|
25
|
+
Project-URL: Issues, https://github.com/anze3db/adventofcode/issues
|
|
26
|
+
Project-URL: Source, https://github.com/anze3db/adventofcode
|
|
27
|
+
Project-URL: Changelog, https://github.com/anze3db/adventofcode/blob/main/CHANGELOG.md
|
|
28
|
+
Project-URL: Mastodon, https://fosstodon.org/@anze3db
|
|
29
|
+
Project-URL: Twitter, https://twitter.com/anze3db
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# 🎄 adventofcode [](https://pypi.org/project/adventofcode) [](https://pypi.org/project/adventofcode)
|
|
33
|
+
|
|
34
|
+
<p align="center">
|
|
35
|
+
<img width="742" height="613" alt="Screenshot 2025-12-02 at 10 04 42" src="https://github.com/anze3db/adventofcode/blob/main/screenshot.png?raw=true" />
|
|
36
|
+
</p>
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Your framework for solving [Advent Of Code](https://adventofcode.com) puzzles 🧩 and benchmarking solutions 🚀
|
|
40
|
+
|
|
41
|
+
* Project scaffolding with `uv run adventofcode init`.
|
|
42
|
+
* Set up your session cookie once, for every year, with `uv run adventofcode login`.
|
|
43
|
+
* Assert and submit your solutions with `uv run adventofcode run`.
|
|
44
|
+
* Benchmark all your solutions with `uv run adventofcode benchmark`.
|
|
45
|
+
* No copy-pasting puzzle inputs or loading inputs from files.
|
|
46
|
+
* Submit the answer immediately when your code returns the result. 🏅
|
|
47
|
+
|
|
48
|
+
------
|
|
49
|
+
|
|
50
|
+
**Table of Contents**
|
|
51
|
+
|
|
52
|
+
- [Setup](#setup)
|
|
53
|
+
- [Session cookie](#session-cookie)
|
|
54
|
+
- [Run and submit your solution](#run-and-submit-your-solution)
|
|
55
|
+
- [Benchmark all your solutions](#benchmark-all-your-solutions)
|
|
56
|
+
- [Using AoC class](#using-aoc-class)
|
|
57
|
+
- [Happy solving 🎄](#happy-solving-)
|
|
58
|
+
- [Similar projects](#similar-projects)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
## Setup
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
uv init
|
|
67
|
+
uv add adventofcode
|
|
68
|
+
uv run adventofcode init
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
If you haven't set up your session cookie yet, `init` asks you to log in (see [Session cookie](#session-cookie)), or you can run `uv run adventofcode login` yourself.
|
|
72
|
+
|
|
73
|
+
`init` generates the scripts for each day (12 puzzles since 2025, 25 before that), a `.env` file with the year, and adds `.env` and the cached puzzle inputs (`.cache*`) to `.gitignore`:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
.
|
|
77
|
+
├── 01.py
|
|
78
|
+
├── 02.py
|
|
79
|
+
├── 03.py
|
|
80
|
+
├── 04.py
|
|
81
|
+
├── 05.py
|
|
82
|
+
├── 06.py
|
|
83
|
+
├── 07.py
|
|
84
|
+
├── 08.py
|
|
85
|
+
├── 09.py
|
|
86
|
+
├── 10.py
|
|
87
|
+
├── 11.py
|
|
88
|
+
├── 12.py
|
|
89
|
+
├── main.py
|
|
90
|
+
├── pyproject.toml
|
|
91
|
+
├── README.md
|
|
92
|
+
└── uv.lock
|
|
93
|
+
|
|
94
|
+
1 directory, 16 files
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
All the generated Python files look like this:
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
"""🎄 Solution for Day 1 of Advent of Code 2026 🎄
|
|
101
|
+
|
|
102
|
+
Usage:
|
|
103
|
+
|
|
104
|
+
uv run adventofcode run 01.py
|
|
105
|
+
"""
|
|
106
|
+
|
|
107
|
+
inp = """your input"""
|
|
108
|
+
part1_asserts = [
|
|
109
|
+
(inp, None),
|
|
110
|
+
]
|
|
111
|
+
part2_asserts = [
|
|
112
|
+
(inp, None),
|
|
113
|
+
]
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def part1(inp: str) -> str | int | None:
|
|
117
|
+
return None
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def part2(inp: str) -> str | int | None:
|
|
121
|
+
return None
|
|
122
|
+
```
|
|
123
|
+
## Session cookie
|
|
124
|
+
|
|
125
|
+
To fetch your puzzle inputs and submit answers, adventofcode needs your adventofcode.com session cookie. Set it up once with
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
uv run adventofcode login
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
It tells you where to find the cookie named `session` in the developer tools. Paste its value, and `login` checks it with adventofcode.com and saves it to `~/.config/adventofcode/session` (only you can read the file), so every Advent of Code folder on your computer uses it. `adventofcode init` offers to log in when no cookie is set up yet.
|
|
132
|
+
|
|
133
|
+
Session cookies expire after about a month. When yours does, `adventofcode run` tells you, and you run `adventofcode login` again.
|
|
134
|
+
|
|
135
|
+
To use a different cookie in one folder, set `AOC_SESSION` in that folder's `.env` file, or in your environment. It takes precedence over the saved one:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
export AOC_SESSION="..."
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Run and submit your solution
|
|
142
|
+
|
|
143
|
+
Implement your solution in `part1` and `part2` functions and run
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
uv run adventofcode run 01.py
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
This will:
|
|
150
|
+
|
|
151
|
+
* 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!
|
|
152
|
+
* If all the `part1_asserts` pass, `part1` will be called with your puzzle input fetched from adventofcode.com using your session cookie.
|
|
153
|
+
* 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.
|
|
154
|
+
* If your answer was correct (or part 1 was already solved), the same process repeats for `part2`. Part 2 is never submitted while part 1 is still unsolved.
|
|
155
|
+
* If adventofcode.com asks you to wait before submitting again, nothing is cached: rerun the command once the wait is over.
|
|
156
|
+
* Running a day before its puzzle unlocks (midnight EST) tells you how long you have left to wait.
|
|
157
|
+
|
|
158
|
+
## Benchmark all your solutions
|
|
159
|
+
|
|
160
|
+
You can benchmark your solutions with
|
|
161
|
+
|
|
162
|
+
```shell
|
|
163
|
+
uv run adventofcode benchmark
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
This runs every day's solution (including variants like `03-numpy.py`), shows the times in a live table in the console, saves the results to `benchmarks.json` and rebuilds the benchmark table in your README.md from them. Commit `benchmarks.json` along with your README.
|
|
167
|
+
|
|
168
|
+
If you are in a hurry you can also benchmark a single day's solution with
|
|
169
|
+
|
|
170
|
+
```shell
|
|
171
|
+
uv run adventofcode benchmark 05.py
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
This only reruns day 5 and keeps the stored results for every other day. The console shows how much faster or slower each solution got since the last run.
|
|
175
|
+
|
|
176
|
+
The README gets one row per day with its fastest solution. If you have more than one solution for a day (`06.py`, `06-numpy.py`, `06-alt.py`), the **Other versions** table compares them all to the fastest one.
|
|
177
|
+
|
|
178
|
+
> **Upgrading from an older version?** The first time, run `uv run adventofcode benchmark` for the whole folder. It benchmarks every day and migrates your README table to the new format. Until then, benchmarking a single day asks you to run the full benchmark instead, so the rest of your table isn't lost.
|
|
179
|
+
|
|
180
|
+
Here's the table it generated for [anze3db/adventofcode2025](https://github.com/anze3db/adventofcode2025), with the 2025 solutions:
|
|
181
|
+
|
|
182
|
+
<!-- BENCHMARK_RESULTS_START -->
|
|
183
|
+
| Day | Stars | Part 1 | Part 2 | Total | Solution |
|
|
184
|
+
|----:|:-----:|-------:|-------:|------:|:---------|
|
|
185
|
+
| 01 | ⭐⭐ | 0.07ms 🟢 | 0.08ms 🟢 | 0.15ms 🟢 | [01.py](https://github.com/anze3db/adventofcode2025/blob/main/01.py) |
|
|
186
|
+
| 02 | ⭐⭐ | 0.10ms 🟢 | 0.12ms 🟢 | 0.22ms 🟢 | [02.py](https://github.com/anze3db/adventofcode2025/blob/main/02.py) |
|
|
187
|
+
| 03 | ⭐⭐ | 0.05ms 🟢 | 0.14ms 🟢 | 0.19ms 🟢 | [03.py](https://github.com/anze3db/adventofcode2025/blob/main/03.py) |
|
|
188
|
+
| 04 | ⭐⭐ | 0.01ms 🟢 | 0.34ms 🟢 | 0.35ms 🟢 | [04-numpy.py](https://github.com/anze3db/adventofcode2025/blob/main/04-numpy.py) · 2 versions |
|
|
189
|
+
| 05 | ⭐⭐ | 0.24ms 🟢 | 0.08ms 🟢 | 0.32ms 🟢 | [05.py](https://github.com/anze3db/adventofcode2025/blob/main/05.py) |
|
|
190
|
+
| 06 | ⭐⭐ | 0.07ms 🟢 | 0.04ms 🟢 | 0.11ms 🟢 | [06.py](https://github.com/anze3db/adventofcode2025/blob/main/06.py) |
|
|
191
|
+
| 07 | ⭐⭐ | 0.02ms 🟢 | 0.11ms 🟢 | 0.13ms 🟢 | [07.py](https://github.com/anze3db/adventofcode2025/blob/main/07.py) |
|
|
192
|
+
| 08 | ⭐⭐ | 0.31ms 🟢 | 0.40ms 🟢 | 0.71ms 🟢 | [08-numpy.py](https://github.com/anze3db/adventofcode2025/blob/main/08-numpy.py) · 2 versions |
|
|
193
|
+
| 09 | ⭐⭐ | 0.07ms 🟢 | 0.47ms 🟢 | 0.54ms 🟢 | [09-numpy.py](https://github.com/anze3db/adventofcode2025/blob/main/09-numpy.py) · 2 versions |
|
|
194
|
+
| 10 | ⭐⭐ | 0.47ms 🟢 | 2.89ms 🟢 | 3.36ms 🟢 | [10-bareiss.py](https://github.com/anze3db/adventofcode2025/blob/main/10-bareiss.py) · 3 versions |
|
|
195
|
+
| 11 | ⭐⭐ | 0.06ms 🟢 | 0.23ms 🟢 | 0.29ms 🟢 | [11.py](https://github.com/anze3db/adventofcode2025/blob/main/11.py) |
|
|
196
|
+
| 12 | ⭐⭐ | 0.04ms 🟢 | - | 0.04ms 🟢 | [12.py](https://github.com/anze3db/adventofcode2025/blob/main/12.py) |
|
|
197
|
+
| **Total** | **24** ⭐ | 1.51ms 🟢 | 4.90ms 🟢 | 6.41ms 🟢 | |
|
|
198
|
+
|
|
199
|
+
**Other versions**
|
|
200
|
+
|
|
201
|
+
| Day | Solution | Stars | Part 1 | Part 2 | Total | vs fastest |
|
|
202
|
+
|----:|:---------|:-----:|-------:|-------:|------:|:-----------|
|
|
203
|
+
| 04 | [04-numpy.py](https://github.com/anze3db/adventofcode2025/blob/main/04-numpy.py) | ⭐⭐ | 0.01ms | 0.34ms | 0.35ms | 🏆 fastest |
|
|
204
|
+
| 04 | [04.py](https://github.com/anze3db/adventofcode2025/blob/main/04.py) | ⭐⭐ | 5.50ms | 12.82ms | 18.32ms | 52× slower |
|
|
205
|
+
| 08 | [08-numpy.py](https://github.com/anze3db/adventofcode2025/blob/main/08-numpy.py) | ⭐⭐ | 0.31ms | 0.40ms | 0.71ms | 🏆 fastest |
|
|
206
|
+
| 08 | [08.py](https://github.com/anze3db/adventofcode2025/blob/main/08.py) | ⭐⭐ | 470.59ms | 448.94ms | 919.53ms | 1295× slower |
|
|
207
|
+
| 09 | [09-numpy.py](https://github.com/anze3db/adventofcode2025/blob/main/09-numpy.py) | ⭐⭐ | 0.07ms | 0.47ms | 0.54ms | 🏆 fastest |
|
|
208
|
+
| 09 | [09.py](https://github.com/anze3db/adventofcode2025/blob/main/09.py) | ⭐⭐ | 9.54ms | 120.99ms | 130.53ms | 242× slower |
|
|
209
|
+
| 10 | [10-bareiss.py](https://github.com/anze3db/adventofcode2025/blob/main/10-bareiss.py) | ⭐⭐ | 0.47ms | 2.89ms | 3.36ms | 🏆 fastest |
|
|
210
|
+
| 10 | [10-numpy.py](https://github.com/anze3db/adventofcode2025/blob/main/10-numpy.py) | ⭐⭐ | 0.62ms | 9.90ms | 10.52ms | 3.1× slower |
|
|
211
|
+
| 10 | [10.py](https://github.com/anze3db/adventofcode2025/blob/main/10.py) | ⭐⭐ | 172.34ms | 209.66ms | 382.00ms | 114× slower |
|
|
212
|
+
|
|
213
|
+
Legend: 🟢 < 100ms · 🟡 100ms - 1s · 🔴 > 1s · ⭐ part solved · ✏️ no answer yet · 🕑 not unlocked yet · ❌ error · ⏰ timed out (> 5 min)
|
|
214
|
+
|
|
215
|
+
Measured with Python 3.14.0 on macOS arm64, last run 2026-11-29.
|
|
216
|
+
<!-- BENCHMARK_RESULTS_END -->
|
|
217
|
+
|
|
218
|
+
## Using AoC class
|
|
219
|
+
|
|
220
|
+
Alternatively, you can build your own workflow using the lower level AoC class
|
|
221
|
+
|
|
222
|
+
```python
|
|
223
|
+
from adventofcode import AoC
|
|
224
|
+
|
|
225
|
+
aoc = AoC() # defaults to AOC_YEAR (or the current year) and parses the day from the filename (e.g. 01.py is day 1)
|
|
226
|
+
|
|
227
|
+
aoc.print_p1() # prints the first part of the puzzle
|
|
228
|
+
inp = aoc.get_input() # returns the input as a string
|
|
229
|
+
# solve the puzzle here
|
|
230
|
+
...
|
|
231
|
+
aoc.submit_p1("part 1 answer") # submits the answer, returns "correct", "incorrect", "too_recent", ...
|
|
232
|
+
aoc.print_p2() # prints the second part of the puzzle
|
|
233
|
+
# solve the puzzle here
|
|
234
|
+
...
|
|
235
|
+
aoc.submit_p2("part 2 answer") # submits the answer to the second part of the puzzle
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
`print_p1()` and `print_p2()` show the puzzle in the terminal with its highlighted parts in bold, as on adventofcode.com. They often matter: in the examples, they mark what counts. To keep the description elsewhere, `get_puzzle()` returns it as plain text, Markdown or HTML:
|
|
239
|
+
|
|
240
|
+
```python
|
|
241
|
+
aoc.get_puzzle(1) # part 1 as plain text
|
|
242
|
+
aoc.get_puzzle(1, format="markdown") # highlights in bold, code as code
|
|
243
|
+
aoc.get_puzzle(2, format="html") # the page's <article> as it is
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
In Markdown, an example with highlighted parts stays an HTML `<pre>` block, since Markdown can't highlight inside a code block. Markdown previews (GitHub, VS Code, ...) still show the highlights.
|
|
247
|
+
|
|
248
|
+
### Happy solving 🎄
|
|
249
|
+
|
|
250
|
+
Enjoy and have fun!
|
|
251
|
+
|
|
252
|
+
### Similar projects
|
|
253
|
+
|
|
254
|
+
* [elf](https://pypi.org/project/elf/)
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# 🎄 adventofcode [](https://pypi.org/project/adventofcode) [](https://pypi.org/project/adventofcode)
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img width="742" height="613" alt="Screenshot 2025-12-02 at 10 04 42" src="https://github.com/anze3db/adventofcode/blob/main/screenshot.png?raw=true" />
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Your framework for solving [Advent Of Code](https://adventofcode.com) puzzles 🧩 and benchmarking solutions 🚀
|
|
9
|
+
|
|
10
|
+
* Project scaffolding with `uv run adventofcode init`.
|
|
11
|
+
* Set up your session cookie once, for every year, with `uv run adventofcode login`.
|
|
12
|
+
* Assert and submit your solutions with `uv run adventofcode run`.
|
|
13
|
+
* Benchmark all your solutions with `uv run adventofcode benchmark`.
|
|
14
|
+
* No copy-pasting puzzle inputs or loading inputs from files.
|
|
15
|
+
* Submit the answer immediately when your code returns the result. 🏅
|
|
16
|
+
|
|
17
|
+
------
|
|
18
|
+
|
|
19
|
+
**Table of Contents**
|
|
20
|
+
|
|
21
|
+
- [Setup](#setup)
|
|
22
|
+
- [Session cookie](#session-cookie)
|
|
23
|
+
- [Run and submit your solution](#run-and-submit-your-solution)
|
|
24
|
+
- [Benchmark all your solutions](#benchmark-all-your-solutions)
|
|
25
|
+
- [Using AoC class](#using-aoc-class)
|
|
26
|
+
- [Happy solving 🎄](#happy-solving-)
|
|
27
|
+
- [Similar projects](#similar-projects)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
## Setup
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
uv init
|
|
36
|
+
uv add adventofcode
|
|
37
|
+
uv run adventofcode init
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
If you haven't set up your session cookie yet, `init` asks you to log in (see [Session cookie](#session-cookie)), or you can run `uv run adventofcode login` yourself.
|
|
41
|
+
|
|
42
|
+
`init` generates the scripts for each day (12 puzzles since 2025, 25 before that), a `.env` file with the year, and adds `.env` and the cached puzzle inputs (`.cache*`) to `.gitignore`:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
.
|
|
46
|
+
├── 01.py
|
|
47
|
+
├── 02.py
|
|
48
|
+
├── 03.py
|
|
49
|
+
├── 04.py
|
|
50
|
+
├── 05.py
|
|
51
|
+
├── 06.py
|
|
52
|
+
├── 07.py
|
|
53
|
+
├── 08.py
|
|
54
|
+
├── 09.py
|
|
55
|
+
├── 10.py
|
|
56
|
+
├── 11.py
|
|
57
|
+
├── 12.py
|
|
58
|
+
├── main.py
|
|
59
|
+
├── pyproject.toml
|
|
60
|
+
├── README.md
|
|
61
|
+
└── uv.lock
|
|
62
|
+
|
|
63
|
+
1 directory, 16 files
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
All the generated Python files look like this:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
"""🎄 Solution for Day 1 of Advent of Code 2026 🎄
|
|
70
|
+
|
|
71
|
+
Usage:
|
|
72
|
+
|
|
73
|
+
uv run adventofcode run 01.py
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
inp = """your input"""
|
|
77
|
+
part1_asserts = [
|
|
78
|
+
(inp, None),
|
|
79
|
+
]
|
|
80
|
+
part2_asserts = [
|
|
81
|
+
(inp, None),
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def part1(inp: str) -> str | int | None:
|
|
86
|
+
return None
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def part2(inp: str) -> str | int | None:
|
|
90
|
+
return None
|
|
91
|
+
```
|
|
92
|
+
## Session cookie
|
|
93
|
+
|
|
94
|
+
To fetch your puzzle inputs and submit answers, adventofcode needs your adventofcode.com session cookie. Set it up once with
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
uv run adventofcode login
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
It tells you where to find the cookie named `session` in the developer tools. Paste its value, and `login` checks it with adventofcode.com and saves it to `~/.config/adventofcode/session` (only you can read the file), so every Advent of Code folder on your computer uses it. `adventofcode init` offers to log in when no cookie is set up yet.
|
|
101
|
+
|
|
102
|
+
Session cookies expire after about a month. When yours does, `adventofcode run` tells you, and you run `adventofcode login` again.
|
|
103
|
+
|
|
104
|
+
To use a different cookie in one folder, set `AOC_SESSION` in that folder's `.env` file, or in your environment. It takes precedence over the saved one:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
export AOC_SESSION="..."
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Run and submit your solution
|
|
111
|
+
|
|
112
|
+
Implement your solution in `part1` and `part2` functions and run
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
uv run adventofcode run 01.py
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
This will:
|
|
119
|
+
|
|
120
|
+
* 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!
|
|
121
|
+
* If all the `part1_asserts` pass, `part1` will be called with your puzzle input fetched from adventofcode.com using your session cookie.
|
|
122
|
+
* 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.
|
|
123
|
+
* If your answer was correct (or part 1 was already solved), the same process repeats for `part2`. Part 2 is never submitted while part 1 is still unsolved.
|
|
124
|
+
* If adventofcode.com asks you to wait before submitting again, nothing is cached: rerun the command once the wait is over.
|
|
125
|
+
* Running a day before its puzzle unlocks (midnight EST) tells you how long you have left to wait.
|
|
126
|
+
|
|
127
|
+
## Benchmark all your solutions
|
|
128
|
+
|
|
129
|
+
You can benchmark your solutions with
|
|
130
|
+
|
|
131
|
+
```shell
|
|
132
|
+
uv run adventofcode benchmark
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
This runs every day's solution (including variants like `03-numpy.py`), shows the times in a live table in the console, saves the results to `benchmarks.json` and rebuilds the benchmark table in your README.md from them. Commit `benchmarks.json` along with your README.
|
|
136
|
+
|
|
137
|
+
If you are in a hurry you can also benchmark a single day's solution with
|
|
138
|
+
|
|
139
|
+
```shell
|
|
140
|
+
uv run adventofcode benchmark 05.py
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
This only reruns day 5 and keeps the stored results for every other day. The console shows how much faster or slower each solution got since the last run.
|
|
144
|
+
|
|
145
|
+
The README gets one row per day with its fastest solution. If you have more than one solution for a day (`06.py`, `06-numpy.py`, `06-alt.py`), the **Other versions** table compares them all to the fastest one.
|
|
146
|
+
|
|
147
|
+
> **Upgrading from an older version?** The first time, run `uv run adventofcode benchmark` for the whole folder. It benchmarks every day and migrates your README table to the new format. Until then, benchmarking a single day asks you to run the full benchmark instead, so the rest of your table isn't lost.
|
|
148
|
+
|
|
149
|
+
Here's the table it generated for [anze3db/adventofcode2025](https://github.com/anze3db/adventofcode2025), with the 2025 solutions:
|
|
150
|
+
|
|
151
|
+
<!-- BENCHMARK_RESULTS_START -->
|
|
152
|
+
| Day | Stars | Part 1 | Part 2 | Total | Solution |
|
|
153
|
+
|----:|:-----:|-------:|-------:|------:|:---------|
|
|
154
|
+
| 01 | ⭐⭐ | 0.07ms 🟢 | 0.08ms 🟢 | 0.15ms 🟢 | [01.py](https://github.com/anze3db/adventofcode2025/blob/main/01.py) |
|
|
155
|
+
| 02 | ⭐⭐ | 0.10ms 🟢 | 0.12ms 🟢 | 0.22ms 🟢 | [02.py](https://github.com/anze3db/adventofcode2025/blob/main/02.py) |
|
|
156
|
+
| 03 | ⭐⭐ | 0.05ms 🟢 | 0.14ms 🟢 | 0.19ms 🟢 | [03.py](https://github.com/anze3db/adventofcode2025/blob/main/03.py) |
|
|
157
|
+
| 04 | ⭐⭐ | 0.01ms 🟢 | 0.34ms 🟢 | 0.35ms 🟢 | [04-numpy.py](https://github.com/anze3db/adventofcode2025/blob/main/04-numpy.py) · 2 versions |
|
|
158
|
+
| 05 | ⭐⭐ | 0.24ms 🟢 | 0.08ms 🟢 | 0.32ms 🟢 | [05.py](https://github.com/anze3db/adventofcode2025/blob/main/05.py) |
|
|
159
|
+
| 06 | ⭐⭐ | 0.07ms 🟢 | 0.04ms 🟢 | 0.11ms 🟢 | [06.py](https://github.com/anze3db/adventofcode2025/blob/main/06.py) |
|
|
160
|
+
| 07 | ⭐⭐ | 0.02ms 🟢 | 0.11ms 🟢 | 0.13ms 🟢 | [07.py](https://github.com/anze3db/adventofcode2025/blob/main/07.py) |
|
|
161
|
+
| 08 | ⭐⭐ | 0.31ms 🟢 | 0.40ms 🟢 | 0.71ms 🟢 | [08-numpy.py](https://github.com/anze3db/adventofcode2025/blob/main/08-numpy.py) · 2 versions |
|
|
162
|
+
| 09 | ⭐⭐ | 0.07ms 🟢 | 0.47ms 🟢 | 0.54ms 🟢 | [09-numpy.py](https://github.com/anze3db/adventofcode2025/blob/main/09-numpy.py) · 2 versions |
|
|
163
|
+
| 10 | ⭐⭐ | 0.47ms 🟢 | 2.89ms 🟢 | 3.36ms 🟢 | [10-bareiss.py](https://github.com/anze3db/adventofcode2025/blob/main/10-bareiss.py) · 3 versions |
|
|
164
|
+
| 11 | ⭐⭐ | 0.06ms 🟢 | 0.23ms 🟢 | 0.29ms 🟢 | [11.py](https://github.com/anze3db/adventofcode2025/blob/main/11.py) |
|
|
165
|
+
| 12 | ⭐⭐ | 0.04ms 🟢 | - | 0.04ms 🟢 | [12.py](https://github.com/anze3db/adventofcode2025/blob/main/12.py) |
|
|
166
|
+
| **Total** | **24** ⭐ | 1.51ms 🟢 | 4.90ms 🟢 | 6.41ms 🟢 | |
|
|
167
|
+
|
|
168
|
+
**Other versions**
|
|
169
|
+
|
|
170
|
+
| Day | Solution | Stars | Part 1 | Part 2 | Total | vs fastest |
|
|
171
|
+
|----:|:---------|:-----:|-------:|-------:|------:|:-----------|
|
|
172
|
+
| 04 | [04-numpy.py](https://github.com/anze3db/adventofcode2025/blob/main/04-numpy.py) | ⭐⭐ | 0.01ms | 0.34ms | 0.35ms | 🏆 fastest |
|
|
173
|
+
| 04 | [04.py](https://github.com/anze3db/adventofcode2025/blob/main/04.py) | ⭐⭐ | 5.50ms | 12.82ms | 18.32ms | 52× slower |
|
|
174
|
+
| 08 | [08-numpy.py](https://github.com/anze3db/adventofcode2025/blob/main/08-numpy.py) | ⭐⭐ | 0.31ms | 0.40ms | 0.71ms | 🏆 fastest |
|
|
175
|
+
| 08 | [08.py](https://github.com/anze3db/adventofcode2025/blob/main/08.py) | ⭐⭐ | 470.59ms | 448.94ms | 919.53ms | 1295× slower |
|
|
176
|
+
| 09 | [09-numpy.py](https://github.com/anze3db/adventofcode2025/blob/main/09-numpy.py) | ⭐⭐ | 0.07ms | 0.47ms | 0.54ms | 🏆 fastest |
|
|
177
|
+
| 09 | [09.py](https://github.com/anze3db/adventofcode2025/blob/main/09.py) | ⭐⭐ | 9.54ms | 120.99ms | 130.53ms | 242× slower |
|
|
178
|
+
| 10 | [10-bareiss.py](https://github.com/anze3db/adventofcode2025/blob/main/10-bareiss.py) | ⭐⭐ | 0.47ms | 2.89ms | 3.36ms | 🏆 fastest |
|
|
179
|
+
| 10 | [10-numpy.py](https://github.com/anze3db/adventofcode2025/blob/main/10-numpy.py) | ⭐⭐ | 0.62ms | 9.90ms | 10.52ms | 3.1× slower |
|
|
180
|
+
| 10 | [10.py](https://github.com/anze3db/adventofcode2025/blob/main/10.py) | ⭐⭐ | 172.34ms | 209.66ms | 382.00ms | 114× slower |
|
|
181
|
+
|
|
182
|
+
Legend: 🟢 < 100ms · 🟡 100ms - 1s · 🔴 > 1s · ⭐ part solved · ✏️ no answer yet · 🕑 not unlocked yet · ❌ error · ⏰ timed out (> 5 min)
|
|
183
|
+
|
|
184
|
+
Measured with Python 3.14.0 on macOS arm64, last run 2026-11-29.
|
|
185
|
+
<!-- BENCHMARK_RESULTS_END -->
|
|
186
|
+
|
|
187
|
+
## Using AoC class
|
|
188
|
+
|
|
189
|
+
Alternatively, you can build your own workflow using the lower level AoC class
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
from adventofcode import AoC
|
|
193
|
+
|
|
194
|
+
aoc = AoC() # defaults to AOC_YEAR (or the current year) and parses the day from the filename (e.g. 01.py is day 1)
|
|
195
|
+
|
|
196
|
+
aoc.print_p1() # prints the first part of the puzzle
|
|
197
|
+
inp = aoc.get_input() # returns the input as a string
|
|
198
|
+
# solve the puzzle here
|
|
199
|
+
...
|
|
200
|
+
aoc.submit_p1("part 1 answer") # submits the answer, returns "correct", "incorrect", "too_recent", ...
|
|
201
|
+
aoc.print_p2() # prints the second part of the puzzle
|
|
202
|
+
# solve the puzzle here
|
|
203
|
+
...
|
|
204
|
+
aoc.submit_p2("part 2 answer") # submits the answer to the second part of the puzzle
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
`print_p1()` and `print_p2()` show the puzzle in the terminal with its highlighted parts in bold, as on adventofcode.com. They often matter: in the examples, they mark what counts. To keep the description elsewhere, `get_puzzle()` returns it as plain text, Markdown or HTML:
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
aoc.get_puzzle(1) # part 1 as plain text
|
|
211
|
+
aoc.get_puzzle(1, format="markdown") # highlights in bold, code as code
|
|
212
|
+
aoc.get_puzzle(2, format="html") # the page's <article> as it is
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
In Markdown, an example with highlighted parts stays an HTML `<pre>` block, since Markdown can't highlight inside a code block. Markdown previews (GitHub, VS Code, ...) still show the highlights.
|
|
216
|
+
|
|
217
|
+
### Happy solving 🎄
|
|
218
|
+
|
|
219
|
+
Enjoy and have fun!
|
|
220
|
+
|
|
221
|
+
### Similar projects
|
|
222
|
+
|
|
223
|
+
* [elf](https://pypi.org/project/elf/)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "adventofcode"
|
|
3
|
-
version = "26.
|
|
3
|
+
version = "26.2"
|
|
4
4
|
description = "Helper utilities for solving Advent of Code puzzles"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.11"
|
|
@@ -115,6 +115,7 @@ ban-relative-imports = "all"
|
|
|
115
115
|
"PLR2004",
|
|
116
116
|
"S101",
|
|
117
117
|
"TID252",
|
|
118
|
+
"RUF001",
|
|
118
119
|
]
|
|
119
120
|
"scripts/release.py" = [
|
|
120
121
|
"DTZ011",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "adventofcode"
|
|
3
3
|
# CalVer: YY.N = the Nth release of 20YY (26.1, 26.2, ..., 27.1). Bumped by scripts/release.py.
|
|
4
|
-
version = "26.
|
|
4
|
+
version = "26.2"
|
|
5
5
|
description = 'Helper utilities for solving Advent of Code puzzles'
|
|
6
6
|
readme = "README.md"
|
|
7
7
|
requires-python = ">=3.11"
|
|
@@ -111,7 +111,7 @@ ban-relative-imports = "all"
|
|
|
111
111
|
|
|
112
112
|
[tool.ruff.lint.per-file-ignores]
|
|
113
113
|
# Tests can use magic values, assertions, and relative imports
|
|
114
|
-
"tests/**/*" = ["PLR2004", "S101", "TID252"]
|
|
114
|
+
"tests/**/*" = ["PLR2004", "S101", "TID252", "RUF001"]
|
|
115
115
|
# The release script is shared with django-tui, potatoq and flakytest-python: keep it in sync rather than lint-clean
|
|
116
116
|
"scripts/release.py" = ["DTZ011", "EM101", "EM102", "FBT001", "FBT002", "PLR0917", "PLW2901", "S603", "T201"]
|
|
117
117
|
"tests/test_release_script.py" = ["ARG001", "ARG005", "PLC0415", "S603", "S607"]
|