Skip to content

Commit 6d20636

Browse files
committed
Automatic inference of PROBLEM_NUM | DAY | YEAR by inferring file paths of call-stack
- Cleanups of AoC 2022.12 solutions
1 parent da0b4cf commit 6d20636

File tree

9 files changed

+68
-311
lines changed

9 files changed

+68
-311
lines changed

adventofcode/2022/01.py

+17-52
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,34 @@
11
# Python Standard Library Imports
22
import copy
33
import heapq
4-
import math
5-
import re
6-
import typing as T
7-
from collections import defaultdict
8-
from dataclasses import dataclass
94

105
from utils import (
116
BaseSolution,
12-
InputConfig,
7+
config,
8+
main,
9+
solution,
1310
)
1411

1512

16-
PROBLEM_NUM = '01'
17-
18-
TEST_MODE = False
19-
# TEST_MODE = True
20-
21-
EXPECTED_ANSWERS = (69912, 208180)
22-
TEST_VARIANT = '' # '', 'b', 'c', 'd', ...
23-
TEST_EXPECTED_ANSWERS = {
13+
config.EXPECTED_ANSWERS = (69912, 208180)
14+
config.TEST_CASES = {
2415
'': (24000, 45000),
25-
'b': (None, None),
26-
'c': (None, None),
2716
}
2817

29-
DEBUGGING = False
30-
DEBUGGING = True
31-
32-
33-
def debug(s):
34-
if DEBUGGING:
35-
print(s)
36-
else:
37-
pass
38-
39-
40-
def main():
41-
input_config = InputConfig(
42-
as_integers=False,
43-
as_comma_separated_integers=False,
44-
as_json=False,
45-
as_groups=True,
46-
as_oneline=False,
47-
as_coordinates=False,
48-
coordinate_delimeter=None,
49-
as_table=False,
50-
row_func=None,
51-
cell_func=None,
52-
)
53-
54-
if TEST_MODE:
55-
input_filename = f'{PROBLEM_NUM}{TEST_VARIANT}.test.in'
56-
expected_answers = TEST_EXPECTED_ANSWERS[TEST_VARIANT]
57-
else:
58-
input_filename = f'{PROBLEM_NUM}.in'
59-
expected_answers = EXPECTED_ANSWERS
60-
61-
solution = Solution(input_filename, input_config, expected_answers)
62-
63-
solution.solve()
64-
solution.report()
18+
config.INPUT_CONFIG.as_integers = False
19+
config.INPUT_CONFIG.as_comma_separated_integers = False
20+
config.INPUT_CONFIG.as_json = False
21+
config.INPUT_CONFIG.as_groups = True
22+
config.INPUT_CONFIG.strip_lines = True
23+
config.INPUT_CONFIG.as_oneline = False
24+
config.INPUT_CONFIG.as_coordinates = False
25+
config.INPUT_CONFIG.coordinate_delimeter = None
26+
config.INPUT_CONFIG.as_table = False
27+
config.INPUT_CONFIG.row_func = None
28+
config.INPUT_CONFIG.cell_func = None
6529

6630

31+
@solution
6732
class Solution(BaseSolution):
6833
def process_data(self):
6934
data = self.data

adventofcode/2022/02.py

+6-50
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,21 @@
11
# Python Standard Library Imports
2-
import typing as T
3-
from dataclasses import dataclass
42
from enum import Enum
53

64
from utils import (
75
BaseSolution,
8-
InputConfig,
6+
config,
7+
main,
8+
solution,
99
)
1010

1111

12-
PROBLEM_NUM = '02'
13-
14-
TEST_MODE = False
15-
# TEST_MODE = True
16-
17-
EXPECTED_ANSWERS = (10994, 12526)
18-
TEST_VARIANT = '' # '', 'b', 'c', 'd', ...
19-
TEST_EXPECTED_ANSWERS = {
12+
config.EXPECTED_ANSWERS = (10994, 12526)
13+
config.TEST_CASES = {
2014
'': (15, 12),
21-
'b': (None, None),
22-
'c': (None, None),
2315
}
2416

25-
DEBUGGING = False
26-
DEBUGGING = True
27-
28-
29-
def debug(s):
30-
if DEBUGGING:
31-
print(s)
32-
else:
33-
pass
34-
35-
36-
def main():
37-
input_config = InputConfig(
38-
as_integers=False,
39-
as_comma_separated_integers=False,
40-
as_json=False,
41-
as_groups=False,
42-
as_oneline=False,
43-
as_coordinates=False,
44-
coordinate_delimeter=None,
45-
as_table=False,
46-
row_func=None,
47-
cell_func=None,
48-
)
49-
50-
if TEST_MODE:
51-
input_filename = f'{PROBLEM_NUM}{TEST_VARIANT}.test.in'
52-
expected_answers = TEST_EXPECTED_ANSWERS[TEST_VARIANT]
53-
else:
54-
input_filename = f'{PROBLEM_NUM}.in'
55-
expected_answers = EXPECTED_ANSWERS
56-
57-
solution = Solution(input_filename, input_config, expected_answers)
58-
59-
solution.solve()
60-
solution.report()
61-
6217

18+
@solution
6319
class Solution(BaseSolution):
6420
def process_data(self):
6521
data = self.data

adventofcode/2022/03.py

+7-51
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,19 @@
1-
# Python Standard Library Imports
2-
import typing as T
3-
41
from utils import (
52
BaseSolution,
6-
InputConfig,
3+
config,
4+
debug,
5+
main,
6+
solution,
77
)
88

99

10-
PROBLEM_NUM = '03'
11-
12-
TEST_MODE = False
13-
# TEST_MODE = True
14-
15-
EXPECTED_ANSWERS = (8233, 2821)
16-
TEST_VARIANT = '' # '', 'b', 'c', 'd', ...
17-
TEST_EXPECTED_ANSWERS = {
10+
config.EXPECTED_ANSWERS = (8233, 2821)
11+
config.TEST_CASES = {
1812
'': (157, 70),
19-
'b': (None, None),
20-
'c': (None, None),
2113
}
2214

23-
DEBUGGING = False
24-
# DEBUGGING = True
25-
26-
27-
def debug(*args):
28-
if DEBUGGING:
29-
print(*args)
30-
else:
31-
pass
32-
33-
34-
def main():
35-
input_config = InputConfig(
36-
as_integers=False,
37-
as_comma_separated_integers=False,
38-
as_json=False,
39-
as_groups=False,
40-
as_oneline=False,
41-
as_coordinates=False,
42-
coordinate_delimeter=None,
43-
as_table=False,
44-
row_func=None,
45-
cell_func=None,
46-
)
47-
48-
if TEST_MODE:
49-
input_filename = f'{PROBLEM_NUM}{TEST_VARIANT}.test.in'
50-
expected_answers = TEST_EXPECTED_ANSWERS[TEST_VARIANT]
51-
else:
52-
input_filename = f'{PROBLEM_NUM}.in'
53-
expected_answers = EXPECTED_ANSWERS
54-
55-
solution = Solution(input_filename, input_config, expected_answers)
56-
57-
solution.solve()
58-
solution.report()
59-
6015

16+
@solution
6117
class Solution(BaseSolution):
6218
def process_data(self):
6319
data = self.data

adventofcode/2022/04.py

+7-48
Original file line numberDiff line numberDiff line change
@@ -3,61 +3,20 @@
33

44
from utils import (
55
BaseSolution,
6-
InputConfig,
6+
config,
7+
debug,
8+
main,
9+
solution,
710
)
811

912

10-
PROBLEM_NUM = '04'
11-
12-
TEST_MODE = False
13-
# TEST_MODE = True
14-
15-
EXPECTED_ANSWERS = (483, 874)
16-
TEST_VARIANT = '' # '', 'b', 'c', 'd', ...
17-
TEST_EXPECTED_ANSWERS = {
13+
config.EXPECTED_ANSWERS = (483, 874)
14+
config.TEST_CASES = {
1815
'': (2, 4),
19-
'b': (None, None),
20-
'c': (None, None),
2116
}
2217

23-
DEBUGGING = False
24-
# DEBUGGING = True
25-
26-
27-
def debug(*args):
28-
if DEBUGGING:
29-
print(*args)
30-
else:
31-
pass
32-
33-
34-
def main():
35-
input_config = InputConfig(
36-
as_integers=False,
37-
as_comma_separated_integers=False,
38-
as_json=False,
39-
as_groups=False,
40-
as_oneline=False,
41-
as_coordinates=False,
42-
coordinate_delimeter=None,
43-
as_table=False,
44-
row_func=None,
45-
cell_func=None,
46-
)
47-
48-
if TEST_MODE:
49-
input_filename = f'{PROBLEM_NUM}{TEST_VARIANT}.test.in'
50-
expected_answers = TEST_EXPECTED_ANSWERS[TEST_VARIANT]
51-
else:
52-
input_filename = f'{PROBLEM_NUM}.in'
53-
expected_answers = EXPECTED_ANSWERS
54-
55-
solution = Solution(input_filename, input_config, expected_answers)
56-
57-
solution.solve()
58-
solution.report()
59-
6018

19+
@solution
6120
class Solution(BaseSolution):
6221
REGEX = re.compile(r'^(?P<a>\d+)-(?P<b>\d+),(?P<c>\d+)-(?P<d>\d+)$')
6322

adventofcode/2022/05.py

-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# Python Standard Library Imports
2-
import copy
3-
import math
4-
import pathlib
52
import re
63
import typing as T
74
from collections import defaultdict
@@ -34,11 +31,6 @@
3431
config.INPUT_CONFIG.cell_func = None
3532

3633

37-
config.YEAR = int(pathlib.Path.cwd().parts[-1])
38-
config.DAY = int(pathlib.Path(__file__).stem)
39-
config.PROBLEM_NUM = str(config.DAY).zfill(2)
40-
41-
4234
@solution
4335
class Solution(BaseSolution):
4436
def process_data(self):

0 commit comments

Comments
 (0)