adventofcode 25.9__tar.gz → 25.10__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-25.9 → adventofcode-25.10}/CHANGELOG.md +33 -0
- {adventofcode-25.9 → adventofcode-25.10}/PKG-INFO +1 -1
- adventofcode-25.10/src/adventofcode/__about__.py +1 -0
- {adventofcode-25.9 → adventofcode-25.10}/src/adventofcode/cli.py +155 -28
- adventofcode-25.9/src/adventofcode/__about__.py +0 -1
- {adventofcode-25.9 → adventofcode-25.10}/.github/workflows/publish.yml +0 -0
- {adventofcode-25.9 → adventofcode-25.10}/.gitignore +0 -0
- {adventofcode-25.9 → adventofcode-25.10}/.pre-commit-config.yaml +0 -0
- {adventofcode-25.9 → adventofcode-25.10}/LICENSE +0 -0
- {adventofcode-25.9 → adventofcode-25.10}/README.md +0 -0
- {adventofcode-25.9 → adventofcode-25.10}/pyproject.toml +0 -0
- {adventofcode-25.9 → adventofcode-25.10}/screenshot.png +0 -0
- {adventofcode-25.9 → adventofcode-25.10}/src/__init__.py +0 -0
- {adventofcode-25.9 → adventofcode-25.10}/src/adventofcode/__init__.py +0 -0
- {adventofcode-25.9 → adventofcode-25.10}/src/adventofcode/utils.py +0 -0
- {adventofcode-25.9 → adventofcode-25.10}/tests/__init__.py +0 -0
- {adventofcode-25.9 → adventofcode-25.10}/tests/test_adventofcode.py +0 -0
|
@@ -5,6 +5,39 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Calendar Versioning](https://calver.org).
|
|
7
7
|
|
|
8
|
+
## [25.10]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
* When you have alternative solutions only the fastest one is now counted in the totals row and the display in the table was improved:
|
|
13
|
+
|
|
14
|
+
| Day | Variant | Status | Part 1 Time | Part 2 Time | Total Time |
|
|
15
|
+
|----:|:--------|:------:|------------:|------------:|-----------:|
|
|
16
|
+
| 01 | | ✅ | 0.54ms 🟢 | 0.63ms 🟢 | 1.17ms 🟢 |
|
|
17
|
+
| 02 | | ✅ | 0.08ms 🟢 | 0.13ms 🟢 | 0.21ms 🟢 |
|
|
18
|
+
| 03 | | ✅ | 0.38ms 🟢 | 0.98ms 🟢 | 1.36ms 🟢 |
|
|
19
|
+
| 04 | numpy | ✅ | 0.80ms 🟢 | 4.48ms 🟢 | 5.28ms 🟢 |
|
|
20
|
+
| ~~04~~ | | ✅ | 5.87ms ⚪ | 14.37ms ⚪ | 20.24ms ⚪ |
|
|
21
|
+
| 05 | | ✅ | 0.28ms 🟢 | 0.09ms 🟢 | 0.37ms 🟢 |
|
|
22
|
+
| 06 | | ✅ | 0.79ms 🟢 | 1.25ms 🟢 | 2.04ms 🟢 |
|
|
23
|
+
| 07 | | ✅ | 1.21ms 🟢 | 1.43ms 🟢 | 2.64ms 🟢 |
|
|
24
|
+
| 08 | | 🕑 | - | - | - |
|
|
25
|
+
| 09 | | 🕑 | - | - | - |
|
|
26
|
+
| 10 | | 🕑 | - | - | - |
|
|
27
|
+
| 11 | | 🕑 | - | - | - |
|
|
28
|
+
| 12 | | 🕑 | - | - | - |
|
|
29
|
+
| **Total** | | | 4.08ms 🟢 | 8.99ms 🟢 | 13.07ms 🟢 |
|
|
30
|
+
|
|
31
|
+
Legend:
|
|
32
|
+
* 🟢 < 100ms
|
|
33
|
+
* 🟡 100ms - 1s
|
|
34
|
+
* 🔴 > 1s
|
|
35
|
+
* ⚪ Not included in total
|
|
36
|
+
|
|
37
|
+
## Fixed
|
|
38
|
+
|
|
39
|
+
* Fix benchmark help text (by @baloncek2662)
|
|
40
|
+
|
|
8
41
|
## [25.9]
|
|
9
42
|
|
|
10
43
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: adventofcode
|
|
3
|
-
Version: 25.
|
|
3
|
+
Version: 25.10
|
|
4
4
|
Summary: Helper utilities for solving Advent of Code puzzles
|
|
5
5
|
Project-URL: Documentation, https://github.com/anze3db/adventofcode#readme
|
|
6
6
|
Project-URL: Issues, https://github.com/anze3db/adventofcode/issues
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "25.10"
|
|
@@ -129,12 +129,15 @@ Color = Literal["green", "yellow", "red", "white"]
|
|
|
129
129
|
@dataclass
|
|
130
130
|
class DayResult:
|
|
131
131
|
day: str
|
|
132
|
+
day_num: str = ""
|
|
133
|
+
variant: str = ""
|
|
132
134
|
part1_time: float = 0.0
|
|
133
135
|
part2_time: float = 0.0
|
|
134
136
|
total_time: float = 0.0
|
|
135
137
|
|
|
136
138
|
status: str = ""
|
|
137
139
|
error: str | None = None
|
|
140
|
+
in_total: bool = True
|
|
138
141
|
|
|
139
142
|
|
|
140
143
|
def time_to_color(seconds: float) -> Color:
|
|
@@ -148,13 +151,30 @@ def time_to_color(seconds: float) -> Color:
|
|
|
148
151
|
return "red"
|
|
149
152
|
|
|
150
153
|
|
|
154
|
+
def split_day_name(day_name: str) -> tuple[str, str]:
|
|
155
|
+
"""Split a day name into (day_number, variant).
|
|
156
|
+
|
|
157
|
+
Examples:
|
|
158
|
+
'01' -> ('01', '')
|
|
159
|
+
'01-alt' -> ('01', 'alt')
|
|
160
|
+
'03-numpy' -> ('03', 'numpy')
|
|
161
|
+
"""
|
|
162
|
+
match = re.match(r"(\d\d)(?:-(.+))?", day_name)
|
|
163
|
+
if match:
|
|
164
|
+
day_num = match.group(1)
|
|
165
|
+
variant = match.group(2) or ""
|
|
166
|
+
return day_num, variant
|
|
167
|
+
return day_name, ""
|
|
168
|
+
|
|
169
|
+
|
|
151
170
|
def run_day(filepath: Path) -> DayResult:
|
|
152
171
|
match = re.match(r"(\d\d)", filepath.stem)
|
|
153
172
|
day_num = int(match.group(1)) if match else 0
|
|
173
|
+
day_num_str, variant = split_day_name(filepath.stem)
|
|
154
174
|
if datetime.date(AOC_YEAR, 12, day_num) > today_est:
|
|
155
|
-
return DayResult(day=filepath.stem, status="🕑")
|
|
175
|
+
return DayResult(day=filepath.stem, day_num=day_num_str, variant=variant, status="🕑")
|
|
156
176
|
|
|
157
|
-
result = DayResult(day=filepath.stem)
|
|
177
|
+
result = DayResult(day=filepath.stem, day_num=day_num_str, variant=variant)
|
|
158
178
|
|
|
159
179
|
if "adventofcode run" in filepath.read_text():
|
|
160
180
|
command = ["adventofcode", "run", str(filepath), "--benchmark"]
|
|
@@ -207,28 +227,53 @@ def run_day(filepath: Path) -> DayResult:
|
|
|
207
227
|
|
|
208
228
|
def build_markdown_table(results: list[DayResult], total_time: float, total_part_1: float, total_part_2: float) -> str:
|
|
209
229
|
"""Generate a markdown table from benchmark results."""
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
230
|
+
# Check if any result has a variant
|
|
231
|
+
has_variants = any(r.variant for r in results)
|
|
232
|
+
|
|
233
|
+
if has_variants:
|
|
234
|
+
lines = [
|
|
235
|
+
"| Day | Variant | Status | Part 1 Time | Part 2 Time | Total Time | ",
|
|
236
|
+
"|----:|:--------|:------:|------------:|------------:|-----------:| ",
|
|
237
|
+
]
|
|
238
|
+
else:
|
|
239
|
+
lines = [
|
|
240
|
+
"| Day | Status | Part 1 Time | Part 2 Time | Total Time | ",
|
|
241
|
+
"|----:|:------:|------------:|------------:|-----------:| ",
|
|
242
|
+
]
|
|
214
243
|
|
|
215
244
|
for r in results:
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
245
|
+
if not r.in_total and r.total_time > 0:
|
|
246
|
+
p1_time = f"{format_time(r.part1_time)} ⚪"
|
|
247
|
+
p2_time = f"{format_time(r.part2_time)} ⚪"
|
|
248
|
+
total = f"{format_time(r.total_time)} ⚪"
|
|
249
|
+
day_display = f"~~{r.day_num}~~"
|
|
250
|
+
variant_display = f"~~{r.variant}~~" if r.variant else ""
|
|
251
|
+
else:
|
|
252
|
+
p1_time = markdown_color(format_time(r.part1_time), time_to_color(r.part1_time))
|
|
253
|
+
p2_time = markdown_color(format_time(r.part2_time), time_to_color(r.part2_time))
|
|
254
|
+
total = markdown_color(format_time(r.total_time), time_to_color(r.total_time))
|
|
255
|
+
day_display = r.day_num
|
|
256
|
+
variant_display = r.variant
|
|
257
|
+
|
|
258
|
+
if has_variants:
|
|
259
|
+
lines.append(f"| {day_display} | {variant_display} | {r.status} | {p1_time} | {p2_time} | {total} |")
|
|
260
|
+
else:
|
|
261
|
+
lines.append(f"| {day_display} | {r.status} | {p1_time} | {p2_time} | {total} |")
|
|
221
262
|
|
|
222
263
|
p1_total = markdown_color(format_time(total_part_1), time_to_color(total_part_1))
|
|
223
264
|
p2_total = markdown_color(format_time(total_part_2), time_to_color(total_part_2))
|
|
224
265
|
total = markdown_color(format_time(total_time), time_to_color(total_time))
|
|
225
266
|
# Add total row
|
|
226
|
-
|
|
267
|
+
if has_variants:
|
|
268
|
+
lines.append(f"| **Total** | | | {p1_total} | {p2_total} | {total} |")
|
|
269
|
+
else:
|
|
270
|
+
lines.append(f"| **Total** | | {p1_total} | {p2_total} | {total} |")
|
|
227
271
|
lines.append("")
|
|
228
272
|
lines.append("Legend:")
|
|
229
273
|
lines.append(" * 🟢 < 100ms")
|
|
230
274
|
lines.append(" * 🟡 100ms - 1s")
|
|
231
275
|
lines.append(" * 🔴 > 1s")
|
|
276
|
+
lines.append(" * ⚪ Not included in total")
|
|
232
277
|
return "\n".join(lines)
|
|
233
278
|
|
|
234
279
|
|
|
@@ -367,8 +412,18 @@ def markdown_color(formatted_time: str, color: Color) -> str:
|
|
|
367
412
|
def build_console_table(
|
|
368
413
|
results: list[DayResult], current_running: str | None, total_part_1: float, total_part_2: float, total_time: float
|
|
369
414
|
) -> Table:
|
|
415
|
+
# Check if any result has a variant
|
|
416
|
+
has_variants = any(r.variant for r in results)
|
|
417
|
+
# Also check if current_running has a variant
|
|
418
|
+
if current_running:
|
|
419
|
+
_, current_variant = split_day_name(current_running)
|
|
420
|
+
if current_variant:
|
|
421
|
+
has_variants = True
|
|
422
|
+
|
|
370
423
|
table = Table(title=f"Advent of Code {AOC_YEAR} Benchmark")
|
|
371
424
|
table.add_column("Day", style="cyan", justify="right")
|
|
425
|
+
if has_variants:
|
|
426
|
+
table.add_column("Variant", style="cyan", justify="left")
|
|
372
427
|
table.add_column("Status", justify="center")
|
|
373
428
|
table.add_column("Part 1", justify="right")
|
|
374
429
|
table.add_column("Part 2", justify="right")
|
|
@@ -379,21 +434,94 @@ def build_console_table(
|
|
|
379
434
|
p2_time = console_color(format_time(r.part2_time), time_to_color(r.part2_time))
|
|
380
435
|
total = console_color(format_time(r.total_time), time_to_color(r.total_time))
|
|
381
436
|
status = r.status
|
|
382
|
-
|
|
437
|
+
if not r.in_total and r.total_time > 0:
|
|
438
|
+
if has_variants:
|
|
439
|
+
table.add_row(
|
|
440
|
+
f"[dim strike]{r.day_num}[/dim strike]",
|
|
441
|
+
f"[dim strike]{r.variant}[/dim strike]",
|
|
442
|
+
f"[dim]{status}[/dim]",
|
|
443
|
+
f"[dim]{format_time(r.part1_time)}[/dim]",
|
|
444
|
+
f"[dim]{format_time(r.part2_time)}[/dim]",
|
|
445
|
+
f"[dim]{format_time(r.total_time)}[/dim]",
|
|
446
|
+
)
|
|
447
|
+
else:
|
|
448
|
+
table.add_row(
|
|
449
|
+
f"[dim strike]{r.day_num}[/dim strike]",
|
|
450
|
+
f"[dim]{status}[/dim]",
|
|
451
|
+
f"[dim]{format_time(r.part1_time)}[/dim]",
|
|
452
|
+
f"[dim]{format_time(r.part2_time)}[/dim]",
|
|
453
|
+
f"[dim]{format_time(r.total_time)}[/dim]",
|
|
454
|
+
)
|
|
455
|
+
elif has_variants:
|
|
456
|
+
table.add_row(r.day_num, r.variant, status, p1_time, p2_time, total)
|
|
457
|
+
else:
|
|
458
|
+
table.add_row(r.day_num, status, p1_time, p2_time, total)
|
|
383
459
|
|
|
384
460
|
if current_running is not None:
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
461
|
+
day_num, variant = split_day_name(current_running)
|
|
462
|
+
if has_variants:
|
|
463
|
+
table.add_row(day_num, variant, "⏳", "...", "...", "...")
|
|
464
|
+
else:
|
|
465
|
+
table.add_row(day_num, "⏳", "...", "...", "...")
|
|
466
|
+
|
|
467
|
+
if has_variants:
|
|
468
|
+
table.add_row(
|
|
469
|
+
"Total",
|
|
470
|
+
"",
|
|
471
|
+
"",
|
|
472
|
+
console_color(format_time(total_part_1), time_to_color(total_part_1)),
|
|
473
|
+
console_color(format_time(total_part_2), time_to_color(total_part_2)),
|
|
474
|
+
console_color(format_time(total_time), time_to_color(total_time)),
|
|
475
|
+
)
|
|
476
|
+
else:
|
|
477
|
+
table.add_row(
|
|
478
|
+
"Total",
|
|
479
|
+
"",
|
|
480
|
+
console_color(format_time(total_part_1), time_to_color(total_part_1)),
|
|
481
|
+
console_color(format_time(total_part_2), time_to_color(total_part_2)),
|
|
482
|
+
console_color(format_time(total_time), time_to_color(total_time)),
|
|
483
|
+
)
|
|
394
484
|
return table
|
|
395
485
|
|
|
396
486
|
|
|
487
|
+
def get_day_number(day_name: str) -> str:
|
|
488
|
+
"""Extract the day number from a filename like '01.py' or '01-alternative.py'."""
|
|
489
|
+
match = re.match(r"(\d\d)", day_name)
|
|
490
|
+
return match.group(1) if match else day_name
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
def select_best_per_day(results: list[DayResult]) -> tuple[list[DayResult], float, float, float]:
|
|
494
|
+
"""Mark the best (fastest) solution for each day as in_total, others as not.
|
|
495
|
+
|
|
496
|
+
Returns updated results and the totals based only on best solutions.
|
|
497
|
+
"""
|
|
498
|
+
day_groups: dict[str, list[DayResult]] = {}
|
|
499
|
+
for r in results:
|
|
500
|
+
day_num = get_day_number(r.day)
|
|
501
|
+
if day_num not in day_groups:
|
|
502
|
+
day_groups[day_num] = []
|
|
503
|
+
day_groups[day_num].append(r)
|
|
504
|
+
|
|
505
|
+
total_time = 0.0
|
|
506
|
+
total_part_1 = 0.0
|
|
507
|
+
total_part_2 = 0.0
|
|
508
|
+
|
|
509
|
+
for group in day_groups.values():
|
|
510
|
+
completed = [r for r in group if r.total_time > 0]
|
|
511
|
+
if completed:
|
|
512
|
+
best = min(completed, key=lambda r: r.total_time)
|
|
513
|
+
for r in group:
|
|
514
|
+
r.in_total = r is best
|
|
515
|
+
total_time += best.total_time
|
|
516
|
+
total_part_1 += best.part1_time
|
|
517
|
+
total_part_2 += best.part2_time
|
|
518
|
+
else:
|
|
519
|
+
for r in group:
|
|
520
|
+
r.in_total = False
|
|
521
|
+
|
|
522
|
+
return results, total_time, total_part_1, total_part_2
|
|
523
|
+
|
|
524
|
+
|
|
397
525
|
def benchmark(path: Path) -> None:
|
|
398
526
|
console.log("[bold]Running benchmarks for Advent of Code[/bold]\n")
|
|
399
527
|
if path.is_dir():
|
|
@@ -433,9 +561,7 @@ def benchmark(path: Path) -> None:
|
|
|
433
561
|
result = run_day(filepath)
|
|
434
562
|
results.append(result)
|
|
435
563
|
|
|
436
|
-
total_part_1
|
|
437
|
-
total_part_2 += result.part2_time
|
|
438
|
-
total_time += result.total_time
|
|
564
|
+
_, total_time, total_part_1, total_part_2 = select_best_per_day(results)
|
|
439
565
|
|
|
440
566
|
live.update(
|
|
441
567
|
build_console_table(
|
|
@@ -552,11 +678,12 @@ def main() -> None:
|
|
|
552
678
|
epilog=dedent("""\
|
|
553
679
|
Examples:
|
|
554
680
|
adventofcode benchmark # Run benchmarks in current directory
|
|
555
|
-
adventofcode benchmark
|
|
556
|
-
adventofcode benchmark
|
|
681
|
+
adventofcode benchmark ./2024 # Run benchmarks in the ./2024 directory
|
|
682
|
+
adventofcode benchmark 02.py # Run benchmarks for day 2 only
|
|
683
|
+
adventofcode benchmark ./2024/02.py # Run benchmarks in the ./2024 directory for day 2 only
|
|
557
684
|
|
|
558
685
|
The benchmark will:
|
|
559
|
-
1. Find
|
|
686
|
+
1. Find selected day files (01.py, 02.py, etc.)
|
|
560
687
|
2. Run each day script (python 01.py, etc.)
|
|
561
688
|
3. Parse execution times from the output
|
|
562
689
|
4. Display a live-updating table in the console
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "25.9"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|