adventofcode 23.0b1__tar.gz → 25.0__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-23.0b1 → adventofcode-25.0}/.github/workflows/publish.yml +1 -1
- {adventofcode-23.0b1 → adventofcode-25.0}/.pre-commit-config.yaml +2 -2
- {adventofcode-23.0b1 → adventofcode-25.0}/CHANGELOG.md +12 -0
- {adventofcode-23.0b1 → adventofcode-25.0}/PKG-INFO +55 -30
- {adventofcode-23.0b1 → adventofcode-25.0}/README.md +50 -25
- {adventofcode-23.0b1 → adventofcode-25.0}/pyproject.toml +9 -5
- adventofcode-25.0/src/adventofcode/__about__.py +1 -0
- {adventofcode-23.0b1 → adventofcode-25.0}/src/adventofcode/__init__.py +15 -49
- adventofcode-25.0/src/adventofcode/cli.py +127 -0
- adventofcode-25.0/tests/test_adventofcode.py +4 -0
- adventofcode-23.0b1/src/adventofcode/__about__.py +0 -1
- adventofcode-23.0b1/tests/test_adventofcode.py +0 -4
- {adventofcode-23.0b1 → adventofcode-25.0}/.gitignore +0 -0
- {adventofcode-23.0b1 → adventofcode-25.0}/LICENSE +0 -0
- {adventofcode-23.0b1 → adventofcode-25.0}/src/__init__.py +0 -0
- {adventofcode-23.0b1 → adventofcode-25.0}/tests/__init__.py +0 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# See https://pre-commit.com/hooks.html for more hooks
|
|
3
3
|
repos:
|
|
4
4
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
5
|
-
rev:
|
|
5
|
+
rev: v6.0.0
|
|
6
6
|
hooks:
|
|
7
7
|
- id: trailing-whitespace
|
|
8
8
|
- id: end-of-file-fixer
|
|
@@ -10,7 +10,7 @@ repos:
|
|
|
10
10
|
- id: check-added-large-files
|
|
11
11
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
12
12
|
# Ruff version.
|
|
13
|
-
rev: v0.
|
|
13
|
+
rev: v0.14.6
|
|
14
14
|
hooks:
|
|
15
15
|
- id: ruff
|
|
16
16
|
- id: ruff-format
|
|
@@ -5,6 +5,18 @@ 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.0]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
* Command line tool for scaffolding all the days (`adventofcode init`)
|
|
13
|
+
* Support for Python 3.13 and 3.14
|
|
14
|
+
|
|
15
|
+
### Removed
|
|
16
|
+
|
|
17
|
+
* `part_1_no_splitlines` and `part_2_no_splitlines` parameters. `part_1` and `part_2` now receive a `str` instead of `list[str]`. This was done to simplify the API.
|
|
18
|
+
* Support for Python 3.8 and 3.9
|
|
19
|
+
|
|
8
20
|
## [23.0b1]
|
|
9
21
|
|
|
10
22
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: adventofcode
|
|
3
|
-
Version:
|
|
3
|
+
Version: 25.0
|
|
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
|
|
@@ -12,14 +12,14 @@ License-Expression: MIT
|
|
|
12
12
|
License-File: LICENSE
|
|
13
13
|
Classifier: Development Status :: 4 - Beta
|
|
14
14
|
Classifier: Programming Language :: Python
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
17
15
|
Classifier: Programming Language :: Python :: 3.10
|
|
18
16
|
Classifier: Programming Language :: Python :: 3.11
|
|
19
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
20
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
21
21
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
22
|
-
Requires-Python: >=3.
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
23
|
Requires-Dist: beautifulsoup4
|
|
24
24
|
Requires-Dist: percache
|
|
25
25
|
Requires-Dist: python-dotenv
|
|
@@ -31,64 +31,89 @@ Description-Content-Type: text/markdown
|
|
|
31
31
|
|
|
32
32
|
Helper utilities for solving Advent of Code puzzles.
|
|
33
33
|
|
|
34
|
+
* Project scaffolding with `adventofcode init`
|
|
34
35
|
* No copy-pasting puzzle inputs into files.
|
|
35
36
|
* No need to use low-level file APIs to read your inputs.
|
|
36
37
|
* Performance reports for example inputs and puzzle inputs.
|
|
37
|
-
* Submit the answer immediately when your code returns the result
|
|
38
|
+
* Submit the answer immediately when your code returns the result 🏅
|
|
38
39
|
|
|
39
40
|
## Usage
|
|
40
41
|
|
|
41
|
-
###
|
|
42
|
+
### Setup
|
|
42
43
|
|
|
43
|
-
Install the package with pip:
|
|
44
44
|
```bash
|
|
45
|
-
|
|
45
|
+
uv init
|
|
46
|
+
uv add adventofcode
|
|
47
|
+
adventofcode init
|
|
46
48
|
```
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
Add the [adventofcode.com](https://adventofcode.com) session cookie value to your env:
|
|
50
|
+
This will generate the scripts for each day:
|
|
51
51
|
|
|
52
52
|
```bash
|
|
53
|
-
|
|
53
|
+
.
|
|
54
|
+
├── 01.py
|
|
55
|
+
├── 02.py
|
|
56
|
+
├── 03.py
|
|
57
|
+
├── 04.py
|
|
58
|
+
├── 05.py
|
|
59
|
+
├── 06.py
|
|
60
|
+
├── 07.py
|
|
61
|
+
├── 08.py
|
|
62
|
+
├── 09.py
|
|
63
|
+
├── 10.py
|
|
64
|
+
├── 11.py
|
|
65
|
+
├── 12.py
|
|
66
|
+
├── main.py
|
|
67
|
+
├── pyproject.toml
|
|
68
|
+
├── README.md
|
|
69
|
+
└── uv.lock
|
|
70
|
+
|
|
71
|
+
1 directory, 16 files
|
|
54
72
|
```
|
|
55
73
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
> [!NOTE]
|
|
59
|
-
> 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()`.
|
|
60
|
-
|
|
61
|
-
### Use a template to solve puzzles
|
|
62
|
-
|
|
63
|
-
I use the following template to start solving puzzles, see my examples in [my repo for 2023](https://github.com/anze3db/adventofcode2023).
|
|
74
|
+
All the py files look like this:
|
|
64
75
|
|
|
65
76
|
```python
|
|
66
77
|
from adventofcode import AoC
|
|
67
78
|
|
|
68
79
|
|
|
69
|
-
def part1(inp):
|
|
80
|
+
def part1(inp: str):
|
|
70
81
|
return None
|
|
71
82
|
|
|
72
83
|
|
|
73
|
-
def part2(inp):
|
|
84
|
+
def part2(inp: str):
|
|
74
85
|
return None
|
|
75
86
|
|
|
76
87
|
|
|
77
88
|
aoc = AoC(part_1=part1, part_2=part2)
|
|
78
89
|
inp = """sample input"""
|
|
79
|
-
|
|
80
|
-
aoc.assert_p1(inp,
|
|
81
|
-
# Run your part1 function on puzzle input and submit the answer returned:
|
|
90
|
+
expected_result = None
|
|
91
|
+
aoc.assert_p1(inp, expected_result)
|
|
82
92
|
aoc.submit_p1()
|
|
83
93
|
|
|
84
|
-
|
|
85
|
-
aoc.assert_p2(inp,
|
|
86
|
-
# Run your part2 function on puzzle input and submit the answer returned:
|
|
94
|
+
expected_result = None
|
|
95
|
+
aoc.assert_p2(inp, expected_result)
|
|
87
96
|
aoc.submit_p2()
|
|
88
97
|
```
|
|
89
98
|
|
|
99
|
+
You write your solution in part1 and part2 functions.
|
|
100
|
+
|
|
101
|
+
`aoc.assert_p1(inp, expected_result)` will call your part1 function with inp and assert that the return matches expected_result.
|
|
102
|
+
|
|
103
|
+
`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.
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
### Set your session cookie
|
|
107
|
+
|
|
108
|
+
Add the [adventofcode.com](https://adventofcode.com) session cookie value to your `.env` file or to your active session:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
export AOC_SESSION="..."
|
|
112
|
+
```
|
|
113
|
+
|
|
90
114
|
> [!NOTE]
|
|
91
|
-
>
|
|
115
|
+
> 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()`.
|
|
116
|
+
|
|
92
117
|
|
|
93
118
|
### Or build your workflow using the AoC class
|
|
94
119
|
|
|
@@ -2,64 +2,89 @@
|
|
|
2
2
|
|
|
3
3
|
Helper utilities for solving Advent of Code puzzles.
|
|
4
4
|
|
|
5
|
+
* Project scaffolding with `adventofcode init`
|
|
5
6
|
* No copy-pasting puzzle inputs into files.
|
|
6
7
|
* No need to use low-level file APIs to read your inputs.
|
|
7
8
|
* Performance reports for example inputs and puzzle inputs.
|
|
8
|
-
* Submit the answer immediately when your code returns the result
|
|
9
|
+
* Submit the answer immediately when your code returns the result 🏅
|
|
9
10
|
|
|
10
11
|
## Usage
|
|
11
12
|
|
|
12
|
-
###
|
|
13
|
+
### Setup
|
|
13
14
|
|
|
14
|
-
Install the package with pip:
|
|
15
15
|
```bash
|
|
16
|
-
|
|
16
|
+
uv init
|
|
17
|
+
uv add adventofcode
|
|
18
|
+
adventofcode init
|
|
17
19
|
```
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Add the [adventofcode.com](https://adventofcode.com) session cookie value to your env:
|
|
21
|
+
This will generate the scripts for each day:
|
|
22
22
|
|
|
23
23
|
```bash
|
|
24
|
-
|
|
24
|
+
.
|
|
25
|
+
├── 01.py
|
|
26
|
+
├── 02.py
|
|
27
|
+
├── 03.py
|
|
28
|
+
├── 04.py
|
|
29
|
+
├── 05.py
|
|
30
|
+
├── 06.py
|
|
31
|
+
├── 07.py
|
|
32
|
+
├── 08.py
|
|
33
|
+
├── 09.py
|
|
34
|
+
├── 10.py
|
|
35
|
+
├── 11.py
|
|
36
|
+
├── 12.py
|
|
37
|
+
├── main.py
|
|
38
|
+
├── pyproject.toml
|
|
39
|
+
├── README.md
|
|
40
|
+
└── uv.lock
|
|
41
|
+
|
|
42
|
+
1 directory, 16 files
|
|
25
43
|
```
|
|
26
44
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
> [!NOTE]
|
|
30
|
-
> 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()`.
|
|
31
|
-
|
|
32
|
-
### Use a template to solve puzzles
|
|
33
|
-
|
|
34
|
-
I use the following template to start solving puzzles, see my examples in [my repo for 2023](https://github.com/anze3db/adventofcode2023).
|
|
45
|
+
All the py files look like this:
|
|
35
46
|
|
|
36
47
|
```python
|
|
37
48
|
from adventofcode import AoC
|
|
38
49
|
|
|
39
50
|
|
|
40
|
-
def part1(inp):
|
|
51
|
+
def part1(inp: str):
|
|
41
52
|
return None
|
|
42
53
|
|
|
43
54
|
|
|
44
|
-
def part2(inp):
|
|
55
|
+
def part2(inp: str):
|
|
45
56
|
return None
|
|
46
57
|
|
|
47
58
|
|
|
48
59
|
aoc = AoC(part_1=part1, part_2=part2)
|
|
49
60
|
inp = """sample input"""
|
|
50
|
-
|
|
51
|
-
aoc.assert_p1(inp,
|
|
52
|
-
# Run your part1 function on puzzle input and submit the answer returned:
|
|
61
|
+
expected_result = None
|
|
62
|
+
aoc.assert_p1(inp, expected_result)
|
|
53
63
|
aoc.submit_p1()
|
|
54
64
|
|
|
55
|
-
|
|
56
|
-
aoc.assert_p2(inp,
|
|
57
|
-
# Run your part2 function on puzzle input and submit the answer returned:
|
|
65
|
+
expected_result = None
|
|
66
|
+
aoc.assert_p2(inp, expected_result)
|
|
58
67
|
aoc.submit_p2()
|
|
59
68
|
```
|
|
60
69
|
|
|
70
|
+
You write your solution in part1 and part2 functions.
|
|
71
|
+
|
|
72
|
+
`aoc.assert_p1(inp, expected_result)` will call your part1 function with inp and assert that the return matches expected_result.
|
|
73
|
+
|
|
74
|
+
`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.
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
### Set your session cookie
|
|
78
|
+
|
|
79
|
+
Add the [adventofcode.com](https://adventofcode.com) session cookie value to your `.env` file or to your active session:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
export AOC_SESSION="..."
|
|
83
|
+
```
|
|
84
|
+
|
|
61
85
|
> [!NOTE]
|
|
62
|
-
>
|
|
86
|
+
> 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()`.
|
|
87
|
+
|
|
63
88
|
|
|
64
89
|
### Or build your workflow using the AoC class
|
|
65
90
|
|
|
@@ -7,7 +7,7 @@ name = "adventofcode"
|
|
|
7
7
|
dynamic = ["version"]
|
|
8
8
|
description = 'Helper utilities for solving Advent of Code puzzles'
|
|
9
9
|
readme = "README.md"
|
|
10
|
-
requires-python = ">=3.
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
11
|
license = "MIT"
|
|
12
12
|
keywords = []
|
|
13
13
|
authors = [
|
|
@@ -16,11 +16,11 @@ authors = [
|
|
|
16
16
|
classifiers = [
|
|
17
17
|
"Development Status :: 4 - Beta",
|
|
18
18
|
"Programming Language :: Python",
|
|
19
|
-
"Programming Language :: Python :: 3.8",
|
|
20
|
-
"Programming Language :: Python :: 3.9",
|
|
21
19
|
"Programming Language :: Python :: 3.10",
|
|
22
20
|
"Programming Language :: Python :: 3.11",
|
|
23
21
|
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Programming Language :: Python :: 3.14",
|
|
24
24
|
"Programming Language :: Python :: Implementation :: CPython",
|
|
25
25
|
"Programming Language :: Python :: Implementation :: PyPy",
|
|
26
26
|
]
|
|
@@ -39,6 +39,10 @@ Source = "https://github.com/anze3db/adventofcode"
|
|
|
39
39
|
Mastodon = "https://fosstodon.org/@anze3db"
|
|
40
40
|
Twitter = "https://twitter.com/anze3db"
|
|
41
41
|
|
|
42
|
+
[project.scripts]
|
|
43
|
+
adventofcode = "adventofcode.cli:main"
|
|
44
|
+
aoc = "adventofcode.cli:main"
|
|
45
|
+
|
|
42
46
|
[tool.hatch.version]
|
|
43
47
|
path = "src/adventofcode/__about__.py"
|
|
44
48
|
|
|
@@ -61,7 +65,7 @@ cov = [
|
|
|
61
65
|
]
|
|
62
66
|
|
|
63
67
|
[[tool.hatch.envs.all.matrix]]
|
|
64
|
-
python = ["3.
|
|
68
|
+
python = ["3.10", "3.11", "3.12", "3.13", "3.14"]
|
|
65
69
|
|
|
66
70
|
[tool.hatch.envs.lint]
|
|
67
71
|
detached = true
|
|
@@ -85,7 +89,7 @@ all = [
|
|
|
85
89
|
]
|
|
86
90
|
|
|
87
91
|
[tool.ruff]
|
|
88
|
-
target-version = "
|
|
92
|
+
target-version = "py310"
|
|
89
93
|
line-length = 120
|
|
90
94
|
select = [
|
|
91
95
|
"A",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "25.0"
|
|
@@ -3,9 +3,10 @@ import os
|
|
|
3
3
|
import re
|
|
4
4
|
import sys
|
|
5
5
|
import time
|
|
6
|
+
from collections.abc import Callable
|
|
6
7
|
from contextlib import contextmanager
|
|
7
8
|
from pathlib import Path
|
|
8
|
-
from typing import Any
|
|
9
|
+
from typing import Any
|
|
9
10
|
|
|
10
11
|
import percache
|
|
11
12
|
import requests
|
|
@@ -21,9 +22,11 @@ AOC_URL = "https://adventofcode.com"
|
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
AOC_SESSION = os.getenv("AOC_SESSION")
|
|
25
|
+
AOC_YEAR = int(os.getenv("AOC_YEAR", str(datetime.datetime.now(tz=datetime.timezone.utc).year)))
|
|
24
26
|
|
|
25
27
|
AOC_NOT_SET_MSG = (
|
|
26
|
-
"Set AOC_SESSION
|
|
28
|
+
"Set AOC_SESSION to your `session` cookie on adventofcode.com. You can add it to your .env file or "
|
|
29
|
+
"export it in your shell (export AOC_SESSION='your session cookie')"
|
|
27
30
|
)
|
|
28
31
|
|
|
29
32
|
|
|
@@ -38,28 +41,24 @@ def print_perf(typ=""):
|
|
|
38
41
|
class AoC:
|
|
39
42
|
def __init__(
|
|
40
43
|
self,
|
|
44
|
+
part_1: Callable[[str], str | int | None],
|
|
45
|
+
part_2: Callable[[str], str | int | None],
|
|
46
|
+
*,
|
|
41
47
|
day: int | None = None,
|
|
42
48
|
year: int | None = None,
|
|
43
|
-
*,
|
|
44
|
-
part_1: Callable[[list[str]], Any] | None = None,
|
|
45
|
-
part_2: Callable[[list[str]], Any] | None = None,
|
|
46
|
-
part_1_no_splitlines: Callable[[str], Any] | None = None,
|
|
47
|
-
part_2_no_splitlines: Callable[[str], Any] | None = None,
|
|
48
49
|
):
|
|
49
50
|
if day is None:
|
|
50
51
|
current_filename = Path(sys.argv[0]).stem
|
|
51
52
|
current_filename_numbers = re.sub(r"[^0-9.]", "", current_filename)
|
|
52
53
|
day = int(current_filename_numbers)
|
|
53
54
|
if year is None:
|
|
54
|
-
year =
|
|
55
|
+
year = AOC_YEAR
|
|
55
56
|
|
|
56
57
|
console.log(f"Solving {day=} {year=}")
|
|
57
58
|
self.day = day
|
|
58
59
|
self.year = year
|
|
59
60
|
self.part_1 = part_1
|
|
60
61
|
self.part_2 = part_2
|
|
61
|
-
self.part_1_no_splitlines = part_1_no_splitlines
|
|
62
|
-
self.part_2_no_splitlines = part_2_no_splitlines
|
|
63
62
|
|
|
64
63
|
def print_p1(self):
|
|
65
64
|
console.log(get_puzzle(self.day, self.year, part=1))
|
|
@@ -68,66 +67,33 @@ class AoC:
|
|
|
68
67
|
console.log(get_puzzle(self.day, self.year, part=2))
|
|
69
68
|
|
|
70
69
|
def get_input(self):
|
|
71
|
-
return get_input(year=self.year, day=self.day).splitlines()
|
|
72
|
-
|
|
73
|
-
def get_input_no_splitlines(self):
|
|
74
70
|
return get_input(year=self.year, day=self.day)
|
|
75
71
|
|
|
76
72
|
def assert_p1(self, inp: str, expected: Any):
|
|
77
|
-
if self.part_1 is None and self.part_1_no_splitlines is None:
|
|
78
|
-
msg = "Set part_1 when initializing AoC()"
|
|
79
|
-
raise Exception(msg)
|
|
80
|
-
|
|
81
73
|
res = None
|
|
82
74
|
with print_perf("assert_p1"):
|
|
83
|
-
|
|
84
|
-
res = self.part_1(inp.splitlines())
|
|
85
|
-
elif self.part_1_no_splitlines is not None:
|
|
86
|
-
res = self.part_1_no_splitlines(inp)
|
|
75
|
+
res = self.part_1(inp)
|
|
87
76
|
|
|
88
77
|
assert res is not None, "Result of part_1 should not be None"
|
|
89
78
|
assert res == expected, f"{res} != {expected}"
|
|
90
79
|
|
|
91
80
|
def assert_p2(self, inp: str, expected: Any):
|
|
92
|
-
if self.part_2 is None and self.part_2_no_splitlines is None:
|
|
93
|
-
msg = "Set part_2 when initializing AoC()"
|
|
94
|
-
raise Exception(msg)
|
|
95
|
-
|
|
96
81
|
res = None
|
|
97
82
|
with print_perf("assert_p2"):
|
|
98
|
-
|
|
99
|
-
res = self.part_2(inp.splitlines())
|
|
100
|
-
elif self.part_2_no_splitlines is not None:
|
|
101
|
-
res = self.part_2_no_splitlines(inp)
|
|
83
|
+
res = self.part_2(inp)
|
|
102
84
|
|
|
103
85
|
assert res is not None, "Result of part_2 should not be None"
|
|
104
86
|
assert res == expected, f"{res} != {expected}"
|
|
105
87
|
|
|
106
88
|
def submit_p1(self, answer: Any | None = None):
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
elif self.part_1 is not None:
|
|
110
|
-
inp = self.get_input()
|
|
111
|
-
with print_perf("submit_p1"):
|
|
112
|
-
answer = self.part_1(inp)
|
|
113
|
-
elif self.part_1_no_splitlines is not None:
|
|
114
|
-
inp = self.get_input_no_splitlines()
|
|
115
|
-
with print_perf("submit_p1"):
|
|
116
|
-
answer = self.part_1_no_splitlines(inp)
|
|
89
|
+
with print_perf("submit_p1"):
|
|
90
|
+
answer = self.part_1(self.get_input())
|
|
117
91
|
|
|
118
92
|
submit(year=self.year, day=self.day, level=1, answer=answer)
|
|
119
93
|
|
|
120
94
|
def submit_p2(self, answer: Any | None = None):
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
elif self.part_2 is not None:
|
|
124
|
-
inp = self.get_input()
|
|
125
|
-
with print_perf("submit_p2"):
|
|
126
|
-
answer = self.part_2(inp)
|
|
127
|
-
elif self.part_2_no_splitlines is not None:
|
|
128
|
-
inp = self.get_input_no_splitlines()
|
|
129
|
-
with print_perf("submit_p2"):
|
|
130
|
-
answer = self.part_2_no_splitlines(inp)
|
|
95
|
+
with print_perf("submit_p2"):
|
|
96
|
+
answer = self.part_2(self.get_input())
|
|
131
97
|
|
|
132
98
|
submit(year=self.year, day=self.day, level=2, answer=answer)
|
|
133
99
|
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import datetime
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from textwrap import dedent
|
|
5
|
+
|
|
6
|
+
from rich.console import Console
|
|
7
|
+
|
|
8
|
+
console = Console()
|
|
9
|
+
TEMPLATE = dedent('''\
|
|
10
|
+
from adventofcode import AoC
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def part1(inp: str) -> str | int | None:
|
|
14
|
+
return None
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def part2(inp: str) -> str | int | None:
|
|
18
|
+
return None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
aoc = AoC(part_1=part1, part_2=part2)
|
|
22
|
+
inp = """sample input"""
|
|
23
|
+
expected_result = None
|
|
24
|
+
aoc.assert_p1(inp, expected_result)
|
|
25
|
+
aoc.submit_p1()
|
|
26
|
+
|
|
27
|
+
expected_result = None
|
|
28
|
+
aoc.assert_p2(inp, expected_result)
|
|
29
|
+
aoc.submit_p2()
|
|
30
|
+
''')
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def generate_templates(year: int, output_dir: Path, num_days: int) -> None:
|
|
34
|
+
"""Generate template files for the specified year."""
|
|
35
|
+
output_dir.mkdir(parents=True, exist_ok=True)
|
|
36
|
+
|
|
37
|
+
console.log(f"Generating templates for Advent of Code {year}")
|
|
38
|
+
|
|
39
|
+
for day in range(1, num_days + 1):
|
|
40
|
+
filename = f"{day:02d}.py"
|
|
41
|
+
filepath = output_dir / filename
|
|
42
|
+
|
|
43
|
+
if filepath.exists():
|
|
44
|
+
console.log(f"Skipping {filename} (already exists)")
|
|
45
|
+
continue
|
|
46
|
+
|
|
47
|
+
filepath.write_text(TEMPLATE)
|
|
48
|
+
console.log(f"Created {filename}")
|
|
49
|
+
|
|
50
|
+
gitignore_path = output_dir / ".gitignore"
|
|
51
|
+
if gitignore_path.exists():
|
|
52
|
+
gitignore_content = gitignore_path.read_text()
|
|
53
|
+
if ".cache" not in gitignore_content:
|
|
54
|
+
with gitignore_path.open("a") as f:
|
|
55
|
+
if not gitignore_content.endswith("\n"):
|
|
56
|
+
f.write("\n")
|
|
57
|
+
f.write(".cache\n")
|
|
58
|
+
console.log("Added .cache to .gitignore")
|
|
59
|
+
if ".env" not in gitignore_content:
|
|
60
|
+
with gitignore_path.open("a") as f:
|
|
61
|
+
if not gitignore_content.endswith("\n"):
|
|
62
|
+
f.write("\n")
|
|
63
|
+
f.write(".env\n")
|
|
64
|
+
console.log("Added .env to .gitignore")
|
|
65
|
+
|
|
66
|
+
env_path = output_dir / ".env"
|
|
67
|
+
if not env_path.exists():
|
|
68
|
+
env_path.write_text(
|
|
69
|
+
"# Set your Advent of Code session cookie below\n"
|
|
70
|
+
"# You can find it in your browser's developer tools after logging in to adventofcode.com. \n"
|
|
71
|
+
"# The name of the cookie is `session`.\n"
|
|
72
|
+
'AOC_SESSION=""\n'
|
|
73
|
+
f"AOC_YEAR={year}\n"
|
|
74
|
+
)
|
|
75
|
+
console.log("Created .env file (remember to set your AOC_SESSION)")
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def main() -> None:
|
|
79
|
+
"""Main entry point for the CLI."""
|
|
80
|
+
parser = argparse.ArgumentParser(
|
|
81
|
+
prog="adventofcode",
|
|
82
|
+
description="Helper utilities for solving Advent of Code puzzles",
|
|
83
|
+
)
|
|
84
|
+
subparsers = parser.add_subparsers(dest="command", help="Available commands")
|
|
85
|
+
|
|
86
|
+
# Init command
|
|
87
|
+
init_parser = subparsers.add_parser(
|
|
88
|
+
"init",
|
|
89
|
+
help="Initialize template files for Advent of Code",
|
|
90
|
+
description=(
|
|
91
|
+
"Initialize all template files for a given year. "
|
|
92
|
+
"Creates one Python file per day with boilerplate code for solving puzzles."
|
|
93
|
+
),
|
|
94
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
95
|
+
epilog=dedent("""\
|
|
96
|
+
Examples:
|
|
97
|
+
adventofcode init # Initialize templates for the current year in current directory
|
|
98
|
+
adventofcode init --year 2023 # Initialize templates for 2023 in the current directory
|
|
99
|
+
adventofcode init --year 2024 ./2024 # Initialize templates for 2024 in the ./2024 directory
|
|
100
|
+
"""),
|
|
101
|
+
)
|
|
102
|
+
init_parser.add_argument(
|
|
103
|
+
"directory",
|
|
104
|
+
type=Path,
|
|
105
|
+
nargs="?",
|
|
106
|
+
default=Path("."),
|
|
107
|
+
help="Directory for generated files (default: current directory)",
|
|
108
|
+
)
|
|
109
|
+
init_parser.add_argument(
|
|
110
|
+
"-y",
|
|
111
|
+
"--year",
|
|
112
|
+
type=int,
|
|
113
|
+
default=datetime.datetime.now(tz=datetime.timezone.utc).year,
|
|
114
|
+
help="Year to generate templates for (default: current year)",
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
args = parser.parse_args()
|
|
118
|
+
|
|
119
|
+
match args.command:
|
|
120
|
+
case "init":
|
|
121
|
+
generate_templates(args.year, args.directory, 12 if args.year >= 2025 else 25)
|
|
122
|
+
case _:
|
|
123
|
+
parser.print_help()
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
if __name__ == "__main__":
|
|
127
|
+
main()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "23.0b1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|