adventofcode 25.3__py3-none-any.whl → 25.5__py3-none-any.whl
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/__about__.py +1 -1
- adventofcode/__init__.py +44 -15
- adventofcode/cli.py +87 -31
- adventofcode/utils.py +10 -0
- adventofcode-25.5.dist-info/METADATA +220 -0
- adventofcode-25.5.dist-info/RECORD +9 -0
- adventofcode-25.3.dist-info/METADATA +0 -181
- adventofcode-25.3.dist-info/RECORD +0 -8
- {adventofcode-25.3.dist-info → adventofcode-25.5.dist-info}/WHEEL +0 -0
- {adventofcode-25.3.dist-info → adventofcode-25.5.dist-info}/entry_points.txt +0 -0
- {adventofcode-25.3.dist-info → adventofcode-25.5.dist-info}/licenses/LICENSE +0 -0
adventofcode/__about__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "25.
|
|
1
|
+
__version__ = "25.5"
|
adventofcode/__init__.py
CHANGED
|
@@ -14,9 +14,11 @@ from bs4 import BeautifulSoup
|
|
|
14
14
|
from dotenv import load_dotenv
|
|
15
15
|
from rich.console import Console
|
|
16
16
|
|
|
17
|
+
from adventofcode.utils import PART_1_RETURN_STR, PART_2_RETURN_STR, format_time
|
|
18
|
+
|
|
17
19
|
load_dotenv(Path(".env").absolute().as_posix())
|
|
18
20
|
cache = percache.Cache(".cache", livesync=True)
|
|
19
|
-
console = Console()
|
|
21
|
+
console = Console(log_path=False)
|
|
20
22
|
|
|
21
23
|
AOC_URL = "https://adventofcode.com"
|
|
22
24
|
|
|
@@ -33,12 +35,23 @@ AOC_NOT_SET_MSG = (
|
|
|
33
35
|
)
|
|
34
36
|
|
|
35
37
|
|
|
38
|
+
class PerfResult:
|
|
39
|
+
"""Container to capture result from within a print_perf context."""
|
|
40
|
+
|
|
41
|
+
def __init__(self):
|
|
42
|
+
self.value = None
|
|
43
|
+
|
|
44
|
+
|
|
36
45
|
@contextmanager
|
|
37
46
|
def print_perf(typ=""):
|
|
38
47
|
t0 = time.perf_counter()
|
|
39
|
-
|
|
48
|
+
result = PerfResult()
|
|
49
|
+
yield result
|
|
40
50
|
diff = time.perf_counter() - t0
|
|
41
|
-
|
|
51
|
+
if result.value is not None:
|
|
52
|
+
console.log(f"{format_time(diff)} to {typ}: {result.value}")
|
|
53
|
+
else:
|
|
54
|
+
console.log(f"{format_time(diff)} to {typ}")
|
|
42
55
|
|
|
43
56
|
|
|
44
57
|
class AoC:
|
|
@@ -74,30 +87,46 @@ class AoC:
|
|
|
74
87
|
|
|
75
88
|
def assert_p1(self, inp: str, expected: Any):
|
|
76
89
|
res = None
|
|
77
|
-
with print_perf("
|
|
90
|
+
with print_perf("assert part1"):
|
|
78
91
|
res = self.part_1(inp)
|
|
79
92
|
|
|
80
|
-
|
|
81
|
-
|
|
93
|
+
if res is None:
|
|
94
|
+
console.log(f"[red]part_1 returned [white]None[/white] for input:[/red]\n{inp[:100]}")
|
|
95
|
+
sys.exit(10)
|
|
96
|
+
if res != expected:
|
|
97
|
+
console.log(
|
|
98
|
+
f"[red]part_1 returned [white]{res}[/white] instead of expected [white]{expected}[/white]"
|
|
99
|
+
f" for input:[/red]\n{inp[:100]}"
|
|
100
|
+
)
|
|
101
|
+
sys.exit(11)
|
|
82
102
|
|
|
83
103
|
def assert_p2(self, inp: str, expected: Any):
|
|
84
104
|
res = None
|
|
85
|
-
with print_perf("
|
|
105
|
+
with print_perf("assert part2"):
|
|
86
106
|
res = self.part_2(inp)
|
|
87
107
|
|
|
88
|
-
|
|
89
|
-
|
|
108
|
+
if res is None:
|
|
109
|
+
console.log(f"[red]part_2 returned [white]None[/white] for input:[/red]\n{inp[:100]}")
|
|
110
|
+
sys.exit(20)
|
|
111
|
+
if res != expected:
|
|
112
|
+
console.log(
|
|
113
|
+
f"[red]part_2 returned [white]{res}[/white] instead of expected [white]{expected}[/white]"
|
|
114
|
+
f" for input:[/red]\n{inp[:100]}"
|
|
115
|
+
)
|
|
116
|
+
sys.exit(21)
|
|
90
117
|
|
|
91
118
|
def submit_p1(self, answer: Any | None = None):
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
119
|
+
inp = self.get_input()
|
|
120
|
+
with print_perf(PART_1_RETURN_STR) as perf:
|
|
121
|
+
answer = self.part_1(inp)
|
|
122
|
+
perf.value = answer
|
|
95
123
|
submit(year=self.year, day=self.day, level=1, answer=answer)
|
|
96
124
|
|
|
97
125
|
def submit_p2(self, answer: Any | None = None):
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
126
|
+
inp = self.get_input()
|
|
127
|
+
with print_perf(PART_2_RETURN_STR) as perf:
|
|
128
|
+
answer = self.part_2(inp)
|
|
129
|
+
perf.value = answer
|
|
101
130
|
submit(year=self.year, day=self.day, level=2, answer=answer)
|
|
102
131
|
|
|
103
132
|
|
adventofcode/cli.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import argparse
|
|
2
2
|
import datetime
|
|
3
|
+
import importlib.util
|
|
3
4
|
import os
|
|
4
5
|
import re
|
|
5
6
|
import subprocess
|
|
@@ -14,6 +15,9 @@ from rich.console import Console
|
|
|
14
15
|
from rich.live import Live
|
|
15
16
|
from rich.table import Table
|
|
16
17
|
|
|
18
|
+
from adventofcode import AoC
|
|
19
|
+
from adventofcode.utils import PART_1_RETURN_STR, PART_2_RETURN_STR, format_time
|
|
20
|
+
|
|
17
21
|
load_dotenv(Path(".env").absolute().as_posix())
|
|
18
22
|
|
|
19
23
|
est = datetime.timezone(datetime.timedelta(hours=-5))
|
|
@@ -21,9 +25,22 @@ today_est = datetime.datetime.now(tz=est).date()
|
|
|
21
25
|
|
|
22
26
|
AOC_YEAR = int(os.getenv("AOC_YEAR", str(today_est.year)))
|
|
23
27
|
|
|
24
|
-
console = Console()
|
|
28
|
+
console = Console(log_path=False)
|
|
25
29
|
TEMPLATE = dedent('''\
|
|
26
|
-
|
|
30
|
+
"""🎄 Solution for Day {day} of Advent of Code {year} 🎄
|
|
31
|
+
|
|
32
|
+
Usage:
|
|
33
|
+
|
|
34
|
+
uv run adventofcode run {day:02d}.py
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
inp = """your input"""
|
|
38
|
+
part1_asserts = [
|
|
39
|
+
(inp, None),
|
|
40
|
+
]
|
|
41
|
+
part2_asserts = [
|
|
42
|
+
(inp, None),
|
|
43
|
+
]
|
|
27
44
|
|
|
28
45
|
|
|
29
46
|
def part1(inp: str) -> str | int | None:
|
|
@@ -32,21 +49,10 @@ TEMPLATE = dedent('''\
|
|
|
32
49
|
|
|
33
50
|
def part2(inp: str) -> str | int | None:
|
|
34
51
|
return None
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
aoc = AoC(part_1=part1, part_2=part2)
|
|
38
|
-
inp = """sample input"""
|
|
39
|
-
expected_result = None
|
|
40
|
-
aoc.assert_p1(inp, expected_result)
|
|
41
|
-
aoc.submit_p1()
|
|
42
|
-
|
|
43
|
-
expected_result = None
|
|
44
|
-
aoc.assert_p2(inp, expected_result)
|
|
45
|
-
aoc.submit_p2()
|
|
46
52
|
''')
|
|
47
53
|
|
|
48
54
|
|
|
49
|
-
def
|
|
55
|
+
def init_templates(year: int, output_dir: Path, num_days: int) -> None:
|
|
50
56
|
"""Generate template files for the specified year."""
|
|
51
57
|
output_dir.mkdir(parents=True, exist_ok=True)
|
|
52
58
|
|
|
@@ -60,7 +66,7 @@ def generate_templates(year: int, output_dir: Path, num_days: int) -> None:
|
|
|
60
66
|
console.log(f"Skipping {filename} (already exists)")
|
|
61
67
|
continue
|
|
62
68
|
|
|
63
|
-
filepath.write_text(TEMPLATE)
|
|
69
|
+
filepath.write_text(TEMPLATE.format(day=day, year=year))
|
|
64
70
|
console.log(f"Created {filename}")
|
|
65
71
|
|
|
66
72
|
gitignore_path = output_dir / ".gitignore"
|
|
@@ -95,19 +101,23 @@ def parse_timing_output(output: str) -> tuple[float, float]:
|
|
|
95
101
|
"""Parse timing information from the AoC class output.
|
|
96
102
|
|
|
97
103
|
The AoC class outputs lines like:
|
|
98
|
-
- "0.
|
|
99
|
-
- "
|
|
104
|
+
- "0.12ms to return part1 result: "
|
|
105
|
+
- "1.45s to return part2 result: "
|
|
100
106
|
"""
|
|
101
107
|
part1_time = part2_time = 0.0
|
|
102
108
|
|
|
103
109
|
for line in output.split("\n"):
|
|
104
|
-
match = re.search(r"(\d+\.\d+)s
|
|
110
|
+
match = re.search(r"(\d+\.\d+)m?s to " + PART_1_RETURN_STR, line)
|
|
105
111
|
if match:
|
|
106
112
|
part1_time = float(match.group(1))
|
|
113
|
+
if "ms" in line:
|
|
114
|
+
part1_time /= 1000.0
|
|
107
115
|
|
|
108
|
-
match = re.search(r"(\d+\.\d+)s
|
|
116
|
+
match = re.search(r"(\d+\.\d+)m?s to " + PART_2_RETURN_STR, line)
|
|
109
117
|
if match:
|
|
110
118
|
part2_time = float(match.group(1))
|
|
119
|
+
if "ms" in line:
|
|
120
|
+
part2_time /= 1000.0
|
|
111
121
|
|
|
112
122
|
return part1_time, part2_time
|
|
113
123
|
|
|
@@ -144,9 +154,13 @@ def run_day(filepath: Path) -> DayResult:
|
|
|
144
154
|
|
|
145
155
|
result = DayResult(day=filepath.stem)
|
|
146
156
|
|
|
157
|
+
if "adventofcode run" in filepath.read_text():
|
|
158
|
+
command = ["adventofcode", "run", str(filepath)]
|
|
159
|
+
else:
|
|
160
|
+
command = [sys.executable, str(filepath)]
|
|
147
161
|
try:
|
|
148
162
|
proc = subprocess.run( # noqa: S603
|
|
149
|
-
|
|
163
|
+
command,
|
|
150
164
|
cwd=filepath.parent,
|
|
151
165
|
capture_output=True,
|
|
152
166
|
text=True,
|
|
@@ -189,14 +203,6 @@ def run_day(filepath: Path) -> DayResult:
|
|
|
189
203
|
return result
|
|
190
204
|
|
|
191
205
|
|
|
192
|
-
def format_time(seconds: float) -> str:
|
|
193
|
-
if seconds <= 0.0:
|
|
194
|
-
return "-"
|
|
195
|
-
if seconds < 1:
|
|
196
|
-
return f"{seconds * 1000:.1f}ms"
|
|
197
|
-
return f"{seconds:.2f}s"
|
|
198
|
-
|
|
199
|
-
|
|
200
206
|
def build_markdown_table(results: list[DayResult], total_time: float, total_part_1: float, total_part_2: float) -> str:
|
|
201
207
|
"""Generate a markdown table from benchmark results."""
|
|
202
208
|
lines = [
|
|
@@ -296,7 +302,7 @@ def build_console_table(
|
|
|
296
302
|
return table
|
|
297
303
|
|
|
298
304
|
|
|
299
|
-
def
|
|
305
|
+
def benchmark(directory: Path) -> None:
|
|
300
306
|
console.log("[bold]Running benchmarks for Advent of Code[/bold]\n")
|
|
301
307
|
|
|
302
308
|
# Find all day files
|
|
@@ -355,6 +361,37 @@ def run_benchmark(directory: Path) -> None:
|
|
|
355
361
|
update_readme(readme_path, results_table)
|
|
356
362
|
|
|
357
363
|
|
|
364
|
+
def run(filepath: Path) -> None:
|
|
365
|
+
# Import the python module on path
|
|
366
|
+
if not filepath.exists():
|
|
367
|
+
console.log(f"[red]File {filepath} does not exist[/red]")
|
|
368
|
+
return
|
|
369
|
+
|
|
370
|
+
console.log(f"[bold]Running {filepath}[/bold]\n")
|
|
371
|
+
spec = importlib.util.spec_from_file_location(filepath.stem, filepath)
|
|
372
|
+
if not spec or not spec.loader:
|
|
373
|
+
console.log(f"[red]Could not load module from {filepath}[/red]")
|
|
374
|
+
return
|
|
375
|
+
module = importlib.util.module_from_spec(spec)
|
|
376
|
+
spec.loader.exec_module(module)
|
|
377
|
+
|
|
378
|
+
aoc = AoC(part_1=module.part1, part_2=module.part2, day=int(filepath.stem), year=AOC_YEAR)
|
|
379
|
+
if hasattr(module, "part1_asserts"):
|
|
380
|
+
for test_input, expected in module.part1_asserts:
|
|
381
|
+
aoc.assert_p1(test_input, expected)
|
|
382
|
+
else:
|
|
383
|
+
console.log("[yellow]No part 1 assertions found[/yellow]\n")
|
|
384
|
+
|
|
385
|
+
aoc.submit_p1()
|
|
386
|
+
if hasattr(module, "part2_asserts"):
|
|
387
|
+
for test_input, expected in module.part2_asserts:
|
|
388
|
+
aoc.assert_p2(test_input, expected)
|
|
389
|
+
else:
|
|
390
|
+
console.log("[yellow]No part 2 assertions found[/yellow]\n")
|
|
391
|
+
|
|
392
|
+
aoc.submit_p2()
|
|
393
|
+
|
|
394
|
+
|
|
358
395
|
def main() -> None:
|
|
359
396
|
"""Main entry point for the CLI."""
|
|
360
397
|
parser = argparse.ArgumentParser(
|
|
@@ -425,13 +462,32 @@ def main() -> None:
|
|
|
425
462
|
help="Directory containing day files (default: current directory)",
|
|
426
463
|
)
|
|
427
464
|
|
|
465
|
+
# Run Command
|
|
466
|
+
run_parser = subparsers.add_parser(
|
|
467
|
+
"run",
|
|
468
|
+
help="Run a specific day's solution",
|
|
469
|
+
description="Run the solution for a specific day and display the output.",
|
|
470
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
471
|
+
epilog=dedent("""\
|
|
472
|
+
Examples:
|
|
473
|
+
adventofcode run 01.py # Run day 1 solution in current directory
|
|
474
|
+
"""),
|
|
475
|
+
)
|
|
476
|
+
run_parser.add_argument(
|
|
477
|
+
"filepath",
|
|
478
|
+
type=Path,
|
|
479
|
+
help="Path to the day file to run (e.g., 01.py)",
|
|
480
|
+
)
|
|
481
|
+
|
|
428
482
|
args = parser.parse_args()
|
|
429
483
|
|
|
430
484
|
match args.command:
|
|
431
485
|
case "init":
|
|
432
|
-
|
|
486
|
+
init_templates(args.year, args.directory, 12 if args.year >= 2025 else 25)
|
|
433
487
|
case "benchmark":
|
|
434
|
-
|
|
488
|
+
benchmark(args.directory)
|
|
489
|
+
case "run":
|
|
490
|
+
run(args.filepath)
|
|
435
491
|
case _:
|
|
436
492
|
parser.print_help()
|
|
437
493
|
|
adventofcode/utils.py
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: adventofcode
|
|
3
|
+
Version: 25.5
|
|
4
|
+
Summary: Helper utilities for solving Advent of Code puzzles
|
|
5
|
+
Project-URL: Documentation, https://github.com/anze3db/adventofcode#readme
|
|
6
|
+
Project-URL: Issues, https://github.com/anze3db/adventofcode/issues
|
|
7
|
+
Project-URL: Source, https://github.com/anze3db/adventofcode
|
|
8
|
+
Project-URL: Mastodon, https://fosstodon.org/@anze3db
|
|
9
|
+
Project-URL: Twitter, https://twitter.com/anze3db
|
|
10
|
+
Author-email: Anže Pečar <anze@pecar.me>
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
21
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: beautifulsoup4
|
|
24
|
+
Requires-Dist: percache
|
|
25
|
+
Requires-Dist: python-dotenv
|
|
26
|
+
Requires-Dist: requests
|
|
27
|
+
Requires-Dist: rich
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# 🎄 adventofcode
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## Your framework for solving and benchmarking Advent of Code puzzles 🧩
|
|
34
|
+
|
|
35
|
+
<p align="center">
|
|
36
|
+
<img src="https://github.com/user-attachments/assets/a00cec03-ab16-47c9-b9bf-a5c9162bcdfd" width="742" alt="benchmark results">
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
## Features
|
|
40
|
+
|
|
41
|
+
* Project scaffolding with `uv run adventofcode init`.
|
|
42
|
+
* Assert and submit your solutions with `uv run adventofcode run`.
|
|
43
|
+
* Benchmark all your solutions with `uv run adventofcode benchmark`.
|
|
44
|
+
* No copy-pasting puzzle inputs or loading inputs from files.
|
|
45
|
+
* Submit the answer immediately when your code returns the result. 🏅
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
### Setup
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
uv init
|
|
53
|
+
uv add adventofcode
|
|
54
|
+
uv run adventofcode init
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
This will generate the scripts for each day:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
.
|
|
61
|
+
├── 01.py
|
|
62
|
+
├── 02.py
|
|
63
|
+
├── 03.py
|
|
64
|
+
├── 04.py
|
|
65
|
+
├── 05.py
|
|
66
|
+
├── 06.py
|
|
67
|
+
├── 07.py
|
|
68
|
+
├── 08.py
|
|
69
|
+
├── 09.py
|
|
70
|
+
├── 10.py
|
|
71
|
+
├── 11.py
|
|
72
|
+
├── 12.py
|
|
73
|
+
├── main.py
|
|
74
|
+
├── pyproject.toml
|
|
75
|
+
├── README.md
|
|
76
|
+
└── uv.lock
|
|
77
|
+
|
|
78
|
+
1 directory, 16 files
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
All the generated Python files look like this:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
"""🎄 Solution for Day 1 of Advent of Code 2025 🎄
|
|
85
|
+
|
|
86
|
+
Usage:
|
|
87
|
+
|
|
88
|
+
uv run adventofcode run 01.py
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
inp = """your input"""
|
|
92
|
+
part1_asserts = [
|
|
93
|
+
(inp, None),
|
|
94
|
+
]
|
|
95
|
+
part2_asserts = [
|
|
96
|
+
(inp, None),
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def part1(inp: str) -> str | int | None:
|
|
101
|
+
return None
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def part2(inp: str) -> str | int | None:
|
|
105
|
+
return None
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Implement your solution in `part1` and `part2` functions and run
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
uv run adventofcode run 01.py
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
This will:
|
|
116
|
+
|
|
117
|
+
* 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!
|
|
118
|
+
* If all the `part1_asserts` pass, `part1` will be called with your puzzle input fetched from adventofcode.com using your session cookie.
|
|
119
|
+
* 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.
|
|
120
|
+
* If your answer was correct the same process repeats for `part2`.
|
|
121
|
+
|
|
122
|
+
### Set your session cookie
|
|
123
|
+
|
|
124
|
+
Add the [adventofcode.com](https://adventofcode.com) session cookie value to your `.env` file:
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
# Set your Advent of Code session cookie below
|
|
128
|
+
# You can find it in your browser's developer tools after logging in to adventofcode.com.
|
|
129
|
+
# The name of the cookie is `session`.
|
|
130
|
+
AOC_SESSION="YOUR_SESSION_COOKIE_HERE"
|
|
131
|
+
AOC_YEAR=2025
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
or to your environment variables:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
export AOC_SESSION="..."
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
> [!NOTE]
|
|
142
|
+
> 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.
|
|
143
|
+
|
|
144
|
+
### Benchmarks
|
|
145
|
+
|
|
146
|
+
You can benchmark your solutions with
|
|
147
|
+
|
|
148
|
+
```shell
|
|
149
|
+
uv run adventofcode benchmark
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
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.
|
|
153
|
+
|
|
154
|
+
Example console output:
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
Example README:
|
|
159
|
+
|
|
160
|
+
<!-- BENCHMARK_RESULTS_START -->
|
|
161
|
+
| Day | Status | Part 1 Time | Part 2 Time | Total Time |
|
|
162
|
+
|:---:|:------:|------------:|------------:|-----------:|
|
|
163
|
+
| 01 | ✅ | 0.28ms 🟢 | 0.41ms 🟢 | 0.69ms 🟢 |
|
|
164
|
+
| 02 | ✅ | 0.76ms 🟢 | 1.13ms 🟢 | 1.89ms 🟢 |
|
|
165
|
+
| 03 | ✅ | 0.15ms 🟢 | 0.33ms 🟢 | 0.48ms 🟢 |
|
|
166
|
+
| 04 | ✅ | 21.43ms 🟢 | 4.79ms 🟢 | 26.22ms 🟢 |
|
|
167
|
+
| 05 | ✅ | 1.95ms 🟢 | 3.51ms 🟢 | 5.46ms 🟢 |
|
|
168
|
+
| 06 | ✅ | 3.04ms 🟢 | 3.91s 🔴 | 3.91s 🔴 |
|
|
169
|
+
| 07 | ✅ | 30.58ms 🟢 | 1.01s 🔴 | 1.04s 🔴 |
|
|
170
|
+
| 08 | ✅ | 0.42ms 🟢 | 0.60ms 🟢 | 1.02ms 🟢 |
|
|
171
|
+
| 09 | ✅ | 5.75ms 🟢 | 1.01s 🔴 | 1.02s 🔴 |
|
|
172
|
+
| 10 | ✅ | 2.85ms 🟢 | 3.05ms 🟢 | 5.90ms 🟢 |
|
|
173
|
+
| 11 | ✅ | 0.97ms 🟢 | 37.60ms 🟢 | 38.57ms 🟢 |
|
|
174
|
+
| 12 | ✅ | 30.75ms 🟢 | 31.96ms 🟢 | 62.71ms 🟢 |
|
|
175
|
+
| 13 | ✅ | 108.79ms 🟡 | 342.44ms 🟡 | 451.23ms 🟡 |
|
|
176
|
+
| 14 | ✅ | 3.03ms 🟢 | 380.22ms 🟡 | 383.25ms 🟡 |
|
|
177
|
+
| 15 | ✅ | 2.28ms 🟢 | 4.71ms 🟢 | 6.99ms 🟢 |
|
|
178
|
+
| 16 | ✅ | 80.55ms 🟢 | 124.54ms 🟡 | 205.09ms 🟡 |
|
|
179
|
+
| 17 | ✅ | 0.02ms 🟢 | 19.99ms 🟢 | 20.01ms 🟢 |
|
|
180
|
+
| 18 | ✅ | 5.66ms 🟢 | 6.98s 🔴 | 6.99s 🔴 |
|
|
181
|
+
| 19 | ✅ | 9.05ms 🟢 | 99.83ms 🟢 | 108.88ms 🟡 |
|
|
182
|
+
| 20 | ✅ | 47.46s 🔴 | 4.28s 🔴 | 51.74s 🔴 |
|
|
183
|
+
| 21 | ✅ | 0.22ms 🟢 | 0.25ms 🟢 | 0.47ms 🟢 |
|
|
184
|
+
| 22 | ✅ | 603.65ms 🟡 | 1.87s 🔴 | 2.47s 🔴 |
|
|
185
|
+
| 23 | ✅ | 223.80ms 🟡 | 222.87ms 🟡 | 446.67ms 🟡 |
|
|
186
|
+
| 24 | ⚠️ | 0.94ms 🟢 | - | 0.94ms 🟢 |
|
|
187
|
+
| 25 | ✅ | 6.02ms 🟢 | - | 6.02ms 🟢 |
|
|
188
|
+
| **Total** | | 48.60s 🔴 | 20.34s 🔴 | 68.94s 🔴 |
|
|
189
|
+
|
|
190
|
+
Legend:
|
|
191
|
+
* 🟢 < 100ms
|
|
192
|
+
* 🟡 100ms - 1s
|
|
193
|
+
* 🔴 > 1s
|
|
194
|
+
<!-- BENCHMARK_RESULTS_END -->
|
|
195
|
+
|
|
196
|
+
### Alternatively, you can build your own workflow using the lower level AoC class
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
from adventofcode import AoC
|
|
200
|
+
|
|
201
|
+
aoc = AoC() # defaults to current year and parses the day from the filename (e.g. 01.py will be day 1)
|
|
202
|
+
|
|
203
|
+
aoc.print_p1() # prints the first part of the puzzle
|
|
204
|
+
inp = aoc.get_input() # returns the input as a string
|
|
205
|
+
# solve the puzzle here
|
|
206
|
+
...
|
|
207
|
+
aoc.submit_p1('part 1 answer') # submits the answer to the first part of the puzzle
|
|
208
|
+
aoc.print_p2() # prints the second part of the puzzle
|
|
209
|
+
# solve the puzzle here
|
|
210
|
+
...
|
|
211
|
+
aoc.submit_p2('part 2 answer') # submits the answer to the second part of the puzzle
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Happy solving 🎄
|
|
215
|
+
|
|
216
|
+
Enjoy and have fun!
|
|
217
|
+
|
|
218
|
+
### Similar projects
|
|
219
|
+
|
|
220
|
+
* [elf](https://pypi.org/project/elf/)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
adventofcode/__about__.py,sha256=ZBIYUAWQxNb4HdL1pHniLRG41vsjZ5zPL3aRyhnWv9M,21
|
|
2
|
+
adventofcode/__init__.py,sha256=Lyu-evu1YGwV94SThnt6-Bo4JP82Vt3JNRrCyjDd7w0,5533
|
|
3
|
+
adventofcode/cli.py,sha256=Ufj65ULzr_fz0l0NdnAVnIKcFgHAfP6LsRCWVd14qZ0,16422
|
|
4
|
+
adventofcode/utils.py,sha256=QJ2AanjoNt_yVI8VZM9plrl9cpHsEhl29NyA4Aqs8Ug,258
|
|
5
|
+
adventofcode-25.5.dist-info/METADATA,sha256=U8ZxUspQnrWM48xInFQUmUXkU7csphgeGf9mHjmO4vw,6917
|
|
6
|
+
adventofcode-25.5.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
7
|
+
adventofcode-25.5.dist-info/entry_points.txt,sha256=Yw9pyDrVVS3XWRcjOv1BnAxkqtJdYoG747A1LysScak,83
|
|
8
|
+
adventofcode-25.5.dist-info/licenses/LICENSE,sha256=7w16SgIHVGYHh8TS_-XnKFvY6aKa_JDtVFoduWtIPTY,1069
|
|
9
|
+
adventofcode-25.5.dist-info/RECORD,,
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: adventofcode
|
|
3
|
-
Version: 25.3
|
|
4
|
-
Summary: Helper utilities for solving Advent of Code puzzles
|
|
5
|
-
Project-URL: Documentation, https://github.com/anze3db/adventofcode#readme
|
|
6
|
-
Project-URL: Issues, https://github.com/anze3db/adventofcode/issues
|
|
7
|
-
Project-URL: Source, https://github.com/anze3db/adventofcode
|
|
8
|
-
Project-URL: Mastodon, https://fosstodon.org/@anze3db
|
|
9
|
-
Project-URL: Twitter, https://twitter.com/anze3db
|
|
10
|
-
Author-email: Anže Pečar <anze@pecar.me>
|
|
11
|
-
License-Expression: MIT
|
|
12
|
-
License-File: LICENSE
|
|
13
|
-
Classifier: Development Status :: 4 - Beta
|
|
14
|
-
Classifier: Programming Language :: Python
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
-
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
21
|
-
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
22
|
-
Requires-Python: >=3.10
|
|
23
|
-
Requires-Dist: beautifulsoup4
|
|
24
|
-
Requires-Dist: percache
|
|
25
|
-
Requires-Dist: python-dotenv
|
|
26
|
-
Requires-Dist: requests
|
|
27
|
-
Requires-Dist: rich
|
|
28
|
-
Description-Content-Type: text/markdown
|
|
29
|
-
|
|
30
|
-
# adventofcode
|
|
31
|
-
|
|
32
|
-
Helper utilities for solving Advent of Code puzzles.
|
|
33
|
-
|
|
34
|
-
* Project scaffolding with `adventofcode init`
|
|
35
|
-
* Benchmark all the days with `adventofcode benchmark`
|
|
36
|
-
* No copy-pasting puzzle inputs into files.
|
|
37
|
-
* No need to use low-level file APIs to read your inputs.
|
|
38
|
-
* Performance reports for example inputs and puzzle inputs.
|
|
39
|
-
* Submit the answer immediately when your code returns the result 🏅
|
|
40
|
-
|
|
41
|
-
## Usage
|
|
42
|
-
|
|
43
|
-
### Setup
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
uv init
|
|
47
|
-
uv add adventofcode
|
|
48
|
-
uv run adventofcode init
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
This will generate the scripts for each day:
|
|
52
|
-
|
|
53
|
-
```bash
|
|
54
|
-
.
|
|
55
|
-
├── 01.py
|
|
56
|
-
├── 02.py
|
|
57
|
-
├── 03.py
|
|
58
|
-
├── 04.py
|
|
59
|
-
├── 05.py
|
|
60
|
-
├── 06.py
|
|
61
|
-
├── 07.py
|
|
62
|
-
├── 08.py
|
|
63
|
-
├── 09.py
|
|
64
|
-
├── 10.py
|
|
65
|
-
├── 11.py
|
|
66
|
-
├── 12.py
|
|
67
|
-
├── main.py
|
|
68
|
-
├── pyproject.toml
|
|
69
|
-
├── README.md
|
|
70
|
-
└── uv.lock
|
|
71
|
-
|
|
72
|
-
1 directory, 16 files
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
All the py files look like this:
|
|
76
|
-
|
|
77
|
-
```python
|
|
78
|
-
from adventofcode import AoC
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
def part1(inp: str):
|
|
82
|
-
return None
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
def part2(inp: str):
|
|
86
|
-
return None
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
aoc = AoC(part_1=part1, part_2=part2)
|
|
90
|
-
inp = """sample input"""
|
|
91
|
-
expected_result = None
|
|
92
|
-
aoc.assert_p1(inp, expected_result)
|
|
93
|
-
aoc.submit_p1()
|
|
94
|
-
|
|
95
|
-
expected_result = None
|
|
96
|
-
aoc.assert_p2(inp, expected_result)
|
|
97
|
-
aoc.submit_p2()
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
You write your solution in part1 and part2 functions.
|
|
101
|
-
|
|
102
|
-
`aoc.assert_p1(inp, expected_result)` will call your part1 function with inp and assert that the return matches expected_result.
|
|
103
|
-
|
|
104
|
-
`aoc.submit_p1()` will fetch your puzzle input from the adventofcode.com, cache it locally and call `part1` with your puzzle input. If `part1` returns a value that isn't `None` that value will be submitted as your puzzle answer.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
### Set your session cookie
|
|
108
|
-
|
|
109
|
-
Add the [adventofcode.com](https://adventofcode.com) session cookie value to your `.env` file or to your active session:
|
|
110
|
-
|
|
111
|
-
```bash
|
|
112
|
-
export AOC_SESSION="..."
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
> [!NOTE]
|
|
116
|
-
> Setting AOC_SESSION will allow you to get your personal puzzle output (`aoc.get_input()`) and submit your answers with `aoc.submit_p1()` and `aoc.submit_p2()`.
|
|
117
|
-
|
|
118
|
-
### Benchmarks
|
|
119
|
-
|
|
120
|
-
You can benchmark your solutions with
|
|
121
|
-
|
|
122
|
-
```shell
|
|
123
|
-
uv run adventofcode benchmark
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
This run each day and parse the timing results from the output. It will print the results in the console and in your README.
|
|
127
|
-
|
|
128
|
-
Example README:
|
|
129
|
-
|
|
130
|
-
| Day | Status | Part 1 Time | Part 2 Time | Total Time |
|
|
131
|
-
|:---:|:------:|------------:|------------:|-----------:|
|
|
132
|
-
| 01 | ✅ | 2.1ms 🟢 | 0.6ms 🟢 | 2.6ms 🟢 |
|
|
133
|
-
| 02 | ✅ | 1.9ms 🟢 | 1.2ms 🟢 | 3.1ms 🟢 |
|
|
134
|
-
| 03 | ✅ | 1.5ms 🟢 | 0.5ms 🟢 | 2.0ms 🟢 |
|
|
135
|
-
| 04 | ✅ | 22.5ms 🟢 | 5.2ms 🟢 | 27.8ms 🟢 |
|
|
136
|
-
| 05 | ✅ | 3.6ms 🟢 | 4.1ms 🟢 | 7.7ms 🟢 |
|
|
137
|
-
| 06 | ✅ | 3.6ms 🟢 | 4.14s 🔴 | 4.14s 🔴 |
|
|
138
|
-
| 07 | ✅ | 33.8ms 🟢 | 1.07s 🔴 | 1.11s 🔴 |
|
|
139
|
-
| 08 | ✅ | 1.0ms 🟢 | 0.7ms 🟢 | 1.7ms 🟢 |
|
|
140
|
-
| 09 | ✅ | 6.3ms 🟢 | 1.08s 🔴 | 1.09s 🔴 |
|
|
141
|
-
| 10 | ✅ | 3.2ms 🟢 | 3.2ms 🟢 | 6.4ms 🟢 |
|
|
142
|
-
| 11 | ✅ | 1.7ms 🟢 | 45.0ms 🟢 | 46.7ms 🟢 |
|
|
143
|
-
| 12 | ✅ | 33.3ms 🟢 | 31.0ms 🟢 | 64.4ms 🟢 |
|
|
144
|
-
| 13 | ✅ | 118.1ms 🟡 | 360.8ms 🟡 | 478.9ms 🟡 |
|
|
145
|
-
| 14 | ✅ | 3.7ms 🟢 | 411.4ms 🟡 | 415.1ms 🟡 |
|
|
146
|
-
| 15 | ✅ | 3.5ms 🟢 | 5.0ms 🟢 | 8.4ms 🟢 |
|
|
147
|
-
| 16 | ✅ | 87.1ms 🟢 | 133.9ms 🟡 | 221.1ms 🟡 |
|
|
148
|
-
| 17 | ✅ | 0.7ms 🟢 | 21.0ms 🟢 | 21.7ms 🟢 |
|
|
149
|
-
| 18 | ✅ | 7.2ms 🟢 | 7.49s 🔴 | 7.50s 🔴 |
|
|
150
|
-
| 19 | ✅ | 9.7ms 🟢 | 111.7ms 🟡 | 121.4ms 🟡 |
|
|
151
|
-
| 20 | ✅ | 50.54s 🔴 | 4.46s 🔴 | 54.99s 🔴 |
|
|
152
|
-
| 21 | ✅ | 0.4ms 🟢 | 0.3ms 🟢 | 0.8ms 🟢 |
|
|
153
|
-
| 22 | ✅ | 603.7ms 🟡 | 1.90s 🔴 | 2.50s 🔴 |
|
|
154
|
-
| 23 | ✅ | 255.0ms 🟡 | 263.4ms 🟡 | 518.4ms 🟡 |
|
|
155
|
-
| 24 | ⚠️ | 1.4ms 🟢 | - | 1.4ms 🟢 |
|
|
156
|
-
| 25 | ✅ | 7.2ms 🟢 | - | 7.2ms 🟢 |
|
|
157
|
-
| **Total** | | 51.75s 🔴 | 21.53s 🔴 | 73.28s 🔴 |
|
|
158
|
-
|
|
159
|
-
Legend:
|
|
160
|
-
* 🟢 < 100ms
|
|
161
|
-
* 🟡 100ms - 1s
|
|
162
|
-
* 🔴 > 1s
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
### Or build your workflow using the AoC class
|
|
166
|
-
|
|
167
|
-
```python
|
|
168
|
-
from adventofcode import AoC
|
|
169
|
-
|
|
170
|
-
aoc = AoC() # defaults to current year and parses the day from the filename (e.g. 01.py will be day 1)
|
|
171
|
-
|
|
172
|
-
aoc.print_p1() # prints the first part of the puzzle
|
|
173
|
-
inp = aoc.get_input() # returns the input as a string
|
|
174
|
-
# solve the puzzle here
|
|
175
|
-
...
|
|
176
|
-
aoc.submit_p1('part 1 answer') # submits the answer to the first part of the puzzle
|
|
177
|
-
aoc.print_p2() # prints the second part of the puzzle
|
|
178
|
-
# solve the puzzle here
|
|
179
|
-
...
|
|
180
|
-
aoc.submit_p2('part 2 answer') # submits the answer to the second part of the puzzle
|
|
181
|
-
```
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
adventofcode/__about__.py,sha256=tVK3AC_S9XFlntEpoGLFjzoRhG2MnZ3nQ3qNv72y2fc,21
|
|
2
|
-
adventofcode/__init__.py,sha256=OqMPnvRc5pcDWMDM4zjwCm4nsOdBohB_1ZSmJz3bXP0,4462
|
|
3
|
-
adventofcode/cli.py,sha256=-y1uIExMoGr0DnAZAgfX45QyAIEFBj1E0koANByyPMs,14439
|
|
4
|
-
adventofcode-25.3.dist-info/METADATA,sha256=CcZnz_EM4ShyvyAbMLmeAbQm11krWS9F36T3jnVvd54,5568
|
|
5
|
-
adventofcode-25.3.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
6
|
-
adventofcode-25.3.dist-info/entry_points.txt,sha256=Yw9pyDrVVS3XWRcjOv1BnAxkqtJdYoG747A1LysScak,83
|
|
7
|
-
adventofcode-25.3.dist-info/licenses/LICENSE,sha256=7w16SgIHVGYHh8TS_-XnKFvY6aKa_JDtVFoduWtIPTY,1069
|
|
8
|
-
adventofcode-25.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|