adventofcode 25.9__tar.gz → 25.11__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.
@@ -5,6 +5,45 @@ 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.11]
9
+
10
+ ### Fixed
11
+
12
+ * Variant column not showing for certain file patterns
13
+
14
+ ## [25.10]
15
+
16
+ ### Added
17
+
18
+ * When you have alternative solutions only the fastest one is now counted in the totals row and the display in the table was improved:
19
+
20
+ | Day | Variant | Status | Part 1 Time | Part 2 Time | Total Time |
21
+ |----:|:--------|:------:|------------:|------------:|-----------:|
22
+ | 01 | | ✅ | 0.54ms 🟢 | 0.63ms 🟢 | 1.17ms 🟢 |
23
+ | 02 | | ✅ | 0.08ms 🟢 | 0.13ms 🟢 | 0.21ms 🟢 |
24
+ | 03 | | ✅ | 0.38ms 🟢 | 0.98ms 🟢 | 1.36ms 🟢 |
25
+ | 04 | numpy | ✅ | 0.80ms 🟢 | 4.48ms 🟢 | 5.28ms 🟢 |
26
+ | ~~04~~ | | ✅ | 5.87ms ⚪ | 14.37ms ⚪ | 20.24ms ⚪ |
27
+ | 05 | | ✅ | 0.28ms 🟢 | 0.09ms 🟢 | 0.37ms 🟢 |
28
+ | 06 | | ✅ | 0.79ms 🟢 | 1.25ms 🟢 | 2.04ms 🟢 |
29
+ | 07 | | ✅ | 1.21ms 🟢 | 1.43ms 🟢 | 2.64ms 🟢 |
30
+ | 08 | | 🕑 | - | - | - |
31
+ | 09 | | 🕑 | - | - | - |
32
+ | 10 | | 🕑 | - | - | - |
33
+ | 11 | | 🕑 | - | - | - |
34
+ | 12 | | 🕑 | - | - | - |
35
+ | **Total** | | | 4.08ms 🟢 | 8.99ms 🟢 | 13.07ms 🟢 |
36
+
37
+ Legend:
38
+ * 🟢 < 100ms
39
+ * 🟡 100ms - 1s
40
+ * 🔴 > 1s
41
+ * ⚪ Not included in total
42
+
43
+ ## Fixed
44
+
45
+ * Fix benchmark help text (by @baloncek2662)
46
+
8
47
  ## [25.9]
9
48
 
10
49
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: adventofcode
3
- Version: 25.9
3
+ Version: 25.11
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.11"
@@ -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,41 @@ 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
+ '03_numpy' -> ('03', 'numpy')
162
+ 'numpy03' -> ('03', 'numpy')
163
+ 'fast03numpy' -> ('03', 'fast-numpy')
164
+ """
165
+ match = re.search(r"(\d\d)", day_name)
166
+ if match:
167
+ day_num = match.group(1)
168
+ # Extract parts before and after the day number
169
+ before = day_name[: match.start()].rstrip("-_")
170
+ after = day_name[match.end() :].lstrip("-_")
171
+ # Combine before and after parts with a hyphen if both exist
172
+ if before and after:
173
+ variant = f"{before}-{after}"
174
+ else:
175
+ variant = before or after
176
+ return day_num, variant
177
+
178
+ return day_name, ""
179
+
180
+
151
181
  def run_day(filepath: Path) -> DayResult:
152
182
  match = re.match(r"(\d\d)", filepath.stem)
153
183
  day_num = int(match.group(1)) if match else 0
184
+ day_num_str, variant = split_day_name(filepath.stem)
154
185
  if datetime.date(AOC_YEAR, 12, day_num) > today_est:
155
- return DayResult(day=filepath.stem, status="🕑")
186
+ return DayResult(day=filepath.stem, day_num=day_num_str, variant=variant, status="🕑")
156
187
 
157
- result = DayResult(day=filepath.stem)
188
+ result = DayResult(day=filepath.stem, day_num=day_num_str, variant=variant)
158
189
 
159
190
  if "adventofcode run" in filepath.read_text():
160
191
  command = ["adventofcode", "run", str(filepath), "--benchmark"]
@@ -207,28 +238,53 @@ def run_day(filepath: Path) -> DayResult:
207
238
 
208
239
  def build_markdown_table(results: list[DayResult], total_time: float, total_part_1: float, total_part_2: float) -> str:
209
240
  """Generate a markdown table from benchmark results."""
210
- lines = [
211
- "| Day | Status | Part 1 Time | Part 2 Time | Total Time | ",
212
- "|:---:|:------:|------------:|------------:|-----------:| ",
213
- ]
241
+ # Check if any result has a variant
242
+ has_variants = any(r.variant for r in results)
243
+
244
+ if has_variants:
245
+ lines = [
246
+ "| Day | Variant | Status | Part 1 Time | Part 2 Time | Total Time | ",
247
+ "|----:|:--------|:------:|------------:|------------:|-----------:| ",
248
+ ]
249
+ else:
250
+ lines = [
251
+ "| Day | Status | Part 1 Time | Part 2 Time | Total Time | ",
252
+ "|----:|:------:|------------:|------------:|-----------:| ",
253
+ ]
214
254
 
215
255
  for r in results:
216
- p1_time = markdown_color(format_time(r.part1_time), time_to_color(r.part1_time))
217
- p2_time = markdown_color(format_time(r.part2_time), time_to_color(r.part2_time))
218
- total = markdown_color(format_time(r.total_time), time_to_color(r.total_time))
219
-
220
- lines.append(f"| {r.day} | {r.status} | {p1_time} | {p2_time} | {total} |")
256
+ if not r.in_total and r.total_time > 0:
257
+ p1_time = f"{format_time(r.part1_time)} ⚪"
258
+ p2_time = f"{format_time(r.part2_time)} ⚪"
259
+ total = f"{format_time(r.total_time)} ⚪"
260
+ day_display = f"~~{r.day_num}~~"
261
+ variant_display = f"~~{r.variant}~~" if r.variant else ""
262
+ else:
263
+ p1_time = markdown_color(format_time(r.part1_time), time_to_color(r.part1_time))
264
+ p2_time = markdown_color(format_time(r.part2_time), time_to_color(r.part2_time))
265
+ total = markdown_color(format_time(r.total_time), time_to_color(r.total_time))
266
+ day_display = r.day_num
267
+ variant_display = r.variant
268
+
269
+ if has_variants:
270
+ lines.append(f"| {day_display} | {variant_display} | {r.status} | {p1_time} | {p2_time} | {total} |")
271
+ else:
272
+ lines.append(f"| {day_display} | {r.status} | {p1_time} | {p2_time} | {total} |")
221
273
 
222
274
  p1_total = markdown_color(format_time(total_part_1), time_to_color(total_part_1))
223
275
  p2_total = markdown_color(format_time(total_part_2), time_to_color(total_part_2))
224
276
  total = markdown_color(format_time(total_time), time_to_color(total_time))
225
277
  # Add total row
226
- lines.append(f"| **Total** | | {p1_total} | {p2_total} | {total} |")
278
+ if has_variants:
279
+ lines.append(f"| **Total** | | | {p1_total} | {p2_total} | {total} |")
280
+ else:
281
+ lines.append(f"| **Total** | | {p1_total} | {p2_total} | {total} |")
227
282
  lines.append("")
228
283
  lines.append("Legend:")
229
284
  lines.append(" * 🟢 < 100ms")
230
285
  lines.append(" * 🟡 100ms - 1s")
231
286
  lines.append(" * 🔴 > 1s")
287
+ lines.append(" * ⚪ Not included in total")
232
288
  return "\n".join(lines)
233
289
 
234
290
 
@@ -367,8 +423,18 @@ def markdown_color(formatted_time: str, color: Color) -> str:
367
423
  def build_console_table(
368
424
  results: list[DayResult], current_running: str | None, total_part_1: float, total_part_2: float, total_time: float
369
425
  ) -> Table:
426
+ # Check if any result has a variant
427
+ has_variants = any(r.variant for r in results)
428
+ # Also check if current_running has a variant
429
+ if current_running:
430
+ _, current_variant = split_day_name(current_running)
431
+ if current_variant:
432
+ has_variants = True
433
+
370
434
  table = Table(title=f"Advent of Code {AOC_YEAR} Benchmark")
371
435
  table.add_column("Day", style="cyan", justify="right")
436
+ if has_variants:
437
+ table.add_column("Variant", style="cyan", justify="left")
372
438
  table.add_column("Status", justify="center")
373
439
  table.add_column("Part 1", justify="right")
374
440
  table.add_column("Part 2", justify="right")
@@ -379,21 +445,94 @@ def build_console_table(
379
445
  p2_time = console_color(format_time(r.part2_time), time_to_color(r.part2_time))
380
446
  total = console_color(format_time(r.total_time), time_to_color(r.total_time))
381
447
  status = r.status
382
- table.add_row(r.day, status, p1_time, p2_time, total)
448
+ if not r.in_total and r.total_time > 0:
449
+ if has_variants:
450
+ table.add_row(
451
+ f"[dim strike]{r.day_num}[/dim strike]",
452
+ f"[dim strike]{r.variant}[/dim strike]",
453
+ f"[dim]{status}[/dim]",
454
+ f"[dim]{format_time(r.part1_time)}[/dim]",
455
+ f"[dim]{format_time(r.part2_time)}[/dim]",
456
+ f"[dim]{format_time(r.total_time)}[/dim]",
457
+ )
458
+ else:
459
+ table.add_row(
460
+ f"[dim strike]{r.day_num}[/dim strike]",
461
+ f"[dim]{status}[/dim]",
462
+ f"[dim]{format_time(r.part1_time)}[/dim]",
463
+ f"[dim]{format_time(r.part2_time)}[/dim]",
464
+ f"[dim]{format_time(r.total_time)}[/dim]",
465
+ )
466
+ elif has_variants:
467
+ table.add_row(r.day_num, r.variant, status, p1_time, p2_time, total)
468
+ else:
469
+ table.add_row(r.day_num, status, p1_time, p2_time, total)
383
470
 
384
471
  if current_running is not None:
385
- table.add_row(str(current_running), "⏳", "...", "...", "...")
386
-
387
- table.add_row(
388
- "Total",
389
- "",
390
- console_color(format_time(total_part_1), time_to_color(total_part_1)),
391
- console_color(format_time(total_part_2), time_to_color(total_part_2)),
392
- console_color(format_time(total_time), time_to_color(total_time)),
393
- )
472
+ day_num, variant = split_day_name(current_running)
473
+ if has_variants:
474
+ table.add_row(day_num, variant, "⏳", "...", "...", "...")
475
+ else:
476
+ table.add_row(day_num, "⏳", "...", "...", "...")
477
+
478
+ if has_variants:
479
+ table.add_row(
480
+ "Total",
481
+ "",
482
+ "",
483
+ console_color(format_time(total_part_1), time_to_color(total_part_1)),
484
+ console_color(format_time(total_part_2), time_to_color(total_part_2)),
485
+ console_color(format_time(total_time), time_to_color(total_time)),
486
+ )
487
+ else:
488
+ table.add_row(
489
+ "Total",
490
+ "",
491
+ console_color(format_time(total_part_1), time_to_color(total_part_1)),
492
+ console_color(format_time(total_part_2), time_to_color(total_part_2)),
493
+ console_color(format_time(total_time), time_to_color(total_time)),
494
+ )
394
495
  return table
395
496
 
396
497
 
498
+ def get_day_number(day_name: str) -> str:
499
+ """Extract the day number from a filename like '01.py' or '01-alternative.py'."""
500
+ match = re.match(r"(\d\d)", day_name)
501
+ return match.group(1) if match else day_name
502
+
503
+
504
+ def select_best_per_day(results: list[DayResult]) -> tuple[list[DayResult], float, float, float]:
505
+ """Mark the best (fastest) solution for each day as in_total, others as not.
506
+
507
+ Returns updated results and the totals based only on best solutions.
508
+ """
509
+ day_groups: dict[str, list[DayResult]] = {}
510
+ for r in results:
511
+ day_num = get_day_number(r.day)
512
+ if day_num not in day_groups:
513
+ day_groups[day_num] = []
514
+ day_groups[day_num].append(r)
515
+
516
+ total_time = 0.0
517
+ total_part_1 = 0.0
518
+ total_part_2 = 0.0
519
+
520
+ for group in day_groups.values():
521
+ completed = [r for r in group if r.total_time > 0]
522
+ if completed:
523
+ best = min(completed, key=lambda r: r.total_time)
524
+ for r in group:
525
+ r.in_total = r is best
526
+ total_time += best.total_time
527
+ total_part_1 += best.part1_time
528
+ total_part_2 += best.part2_time
529
+ else:
530
+ for r in group:
531
+ r.in_total = False
532
+
533
+ return results, total_time, total_part_1, total_part_2
534
+
535
+
397
536
  def benchmark(path: Path) -> None:
398
537
  console.log("[bold]Running benchmarks for Advent of Code[/bold]\n")
399
538
  if path.is_dir():
@@ -433,9 +572,7 @@ def benchmark(path: Path) -> None:
433
572
  result = run_day(filepath)
434
573
  results.append(result)
435
574
 
436
- total_part_1 += result.part1_time
437
- total_part_2 += result.part2_time
438
- total_time += result.total_time
575
+ _, total_time, total_part_1, total_part_2 = select_best_per_day(results)
439
576
 
440
577
  live.update(
441
578
  build_console_table(
@@ -552,11 +689,12 @@ def main() -> None:
552
689
  epilog=dedent("""\
553
690
  Examples:
554
691
  adventofcode benchmark # Run benchmarks in current directory
555
- adventofcode benchmark -d ./2024 # Run benchmarks in the ./2024 directory
556
- adventofcode benchmark -d ./2024 2 # Run benchmarks in the ./2024 directory for day 2 only
692
+ adventofcode benchmark ./2024 # Run benchmarks in the ./2024 directory
693
+ adventofcode benchmark 02.py # Run benchmarks for day 2 only
694
+ adventofcode benchmark ./2024/02.py # Run benchmarks in the ./2024 directory for day 2 only
557
695
 
558
696
  The benchmark will:
559
- 1. Find all day files (01.py, 02.py, etc.)
697
+ 1. Find selected day files (01.py, 02.py, etc.)
560
698
  2. Run each day script (python 01.py, etc.)
561
699
  3. Parse execution times from the output
562
700
  4. Display a live-updating table in the console
@@ -0,0 +1,28 @@
1
+ import pytest
2
+
3
+ from src.adventofcode.cli import split_day_name
4
+
5
+
6
+ def test_version():
7
+ from src.adventofcode.__about__ import __version__ # noqa: PLC0415
8
+
9
+ assert __version__
10
+
11
+
12
+ @pytest.mark.parametrize(
13
+ ("day_name", "expected"),
14
+ [
15
+ ("01", ("01", "")),
16
+ ("01-alt", ("01", "alt")),
17
+ ("03-numpy", ("03", "numpy")),
18
+ ("03_numpy", ("03", "numpy")),
19
+ ("fast-03", ("03", "fast")),
20
+ ("maybe-03-fast", ("03", "maybe-fast")),
21
+ ("fast03", ("03", "fast")),
22
+ ("maybe03fast", ("03", "maybe-fast")),
23
+ ("maybe_03_fast", ("03", "maybe-fast")),
24
+ ("numpy03", ("03", "numpy")),
25
+ ],
26
+ )
27
+ def test_split_day_name(day_name: str, expected: tuple[str, str]):
28
+ assert split_day_name(day_name) == expected
@@ -1 +0,0 @@
1
- __version__ = "25.9"
@@ -1,4 +0,0 @@
1
- def test_version():
2
- from src.adventofcode.__about__ import __version__ # noqa: PLC0415
3
-
4
- assert __version__
File without changes
File without changes
File without changes
File without changes
File without changes