Skip to content

Commit

Permalink
Automatic inference of PROBLEM_NUM | DAY | YEAR by inferring file pat…
Browse files Browse the repository at this point in the history
…hs of call-stack

- Cleanups of AoC 2022.12 solutions
  • Loading branch information
jontsai committed Dec 8, 2022
1 parent da0b4cf commit 6d20636
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 311 deletions.
69 changes: 17 additions & 52 deletions adventofcode/2022/01.py
Original file line number Diff line number Diff line change
@@ -1,69 +1,34 @@
# Python Standard Library Imports
import copy
import heapq
import math
import re
import typing as T
from collections import defaultdict
from dataclasses import dataclass

from utils import (
BaseSolution,
InputConfig,
config,
main,
solution,
)


PROBLEM_NUM = '01'

TEST_MODE = False
# TEST_MODE = True

EXPECTED_ANSWERS = (69912, 208180)
TEST_VARIANT = '' # '', 'b', 'c', 'd', ...
TEST_EXPECTED_ANSWERS = {
config.EXPECTED_ANSWERS = (69912, 208180)
config.TEST_CASES = {
'': (24000, 45000),
'b': (None, None),
'c': (None, None),
}

DEBUGGING = False
DEBUGGING = True


def debug(s):
if DEBUGGING:
print(s)
else:
pass


def main():
input_config = InputConfig(
as_integers=False,
as_comma_separated_integers=False,
as_json=False,
as_groups=True,
as_oneline=False,
as_coordinates=False,
coordinate_delimeter=None,
as_table=False,
row_func=None,
cell_func=None,
)

if TEST_MODE:
input_filename = f'{PROBLEM_NUM}{TEST_VARIANT}.test.in'
expected_answers = TEST_EXPECTED_ANSWERS[TEST_VARIANT]
else:
input_filename = f'{PROBLEM_NUM}.in'
expected_answers = EXPECTED_ANSWERS

solution = Solution(input_filename, input_config, expected_answers)

solution.solve()
solution.report()
config.INPUT_CONFIG.as_integers = False
config.INPUT_CONFIG.as_comma_separated_integers = False
config.INPUT_CONFIG.as_json = False
config.INPUT_CONFIG.as_groups = True
config.INPUT_CONFIG.strip_lines = True
config.INPUT_CONFIG.as_oneline = False
config.INPUT_CONFIG.as_coordinates = False
config.INPUT_CONFIG.coordinate_delimeter = None
config.INPUT_CONFIG.as_table = False
config.INPUT_CONFIG.row_func = None
config.INPUT_CONFIG.cell_func = None


@solution
class Solution(BaseSolution):
def process_data(self):
data = self.data
Expand Down
56 changes: 6 additions & 50 deletions adventofcode/2022/02.py
Original file line number Diff line number Diff line change
@@ -1,65 +1,21 @@
# Python Standard Library Imports
import typing as T
from dataclasses import dataclass
from enum import Enum

from utils import (
BaseSolution,
InputConfig,
config,
main,
solution,
)


PROBLEM_NUM = '02'

TEST_MODE = False
# TEST_MODE = True

EXPECTED_ANSWERS = (10994, 12526)
TEST_VARIANT = '' # '', 'b', 'c', 'd', ...
TEST_EXPECTED_ANSWERS = {
config.EXPECTED_ANSWERS = (10994, 12526)
config.TEST_CASES = {
'': (15, 12),
'b': (None, None),
'c': (None, None),
}

DEBUGGING = False
DEBUGGING = True


def debug(s):
if DEBUGGING:
print(s)
else:
pass


def main():
input_config = InputConfig(
as_integers=False,
as_comma_separated_integers=False,
as_json=False,
as_groups=False,
as_oneline=False,
as_coordinates=False,
coordinate_delimeter=None,
as_table=False,
row_func=None,
cell_func=None,
)

if TEST_MODE:
input_filename = f'{PROBLEM_NUM}{TEST_VARIANT}.test.in'
expected_answers = TEST_EXPECTED_ANSWERS[TEST_VARIANT]
else:
input_filename = f'{PROBLEM_NUM}.in'
expected_answers = EXPECTED_ANSWERS

solution = Solution(input_filename, input_config, expected_answers)

solution.solve()
solution.report()


@solution
class Solution(BaseSolution):
def process_data(self):
data = self.data
Expand Down
58 changes: 7 additions & 51 deletions adventofcode/2022/03.py
Original file line number Diff line number Diff line change
@@ -1,63 +1,19 @@
# Python Standard Library Imports
import typing as T

from utils import (
BaseSolution,
InputConfig,
config,
debug,
main,
solution,
)


PROBLEM_NUM = '03'

TEST_MODE = False
# TEST_MODE = True

EXPECTED_ANSWERS = (8233, 2821)
TEST_VARIANT = '' # '', 'b', 'c', 'd', ...
TEST_EXPECTED_ANSWERS = {
config.EXPECTED_ANSWERS = (8233, 2821)
config.TEST_CASES = {
'': (157, 70),
'b': (None, None),
'c': (None, None),
}

DEBUGGING = False
# DEBUGGING = True


def debug(*args):
if DEBUGGING:
print(*args)
else:
pass


def main():
input_config = InputConfig(
as_integers=False,
as_comma_separated_integers=False,
as_json=False,
as_groups=False,
as_oneline=False,
as_coordinates=False,
coordinate_delimeter=None,
as_table=False,
row_func=None,
cell_func=None,
)

if TEST_MODE:
input_filename = f'{PROBLEM_NUM}{TEST_VARIANT}.test.in'
expected_answers = TEST_EXPECTED_ANSWERS[TEST_VARIANT]
else:
input_filename = f'{PROBLEM_NUM}.in'
expected_answers = EXPECTED_ANSWERS

solution = Solution(input_filename, input_config, expected_answers)

solution.solve()
solution.report()


@solution
class Solution(BaseSolution):
def process_data(self):
data = self.data
Expand Down
55 changes: 7 additions & 48 deletions adventofcode/2022/04.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,20 @@

from utils import (
BaseSolution,
InputConfig,
config,
debug,
main,
solution,
)


PROBLEM_NUM = '04'

TEST_MODE = False
# TEST_MODE = True

EXPECTED_ANSWERS = (483, 874)
TEST_VARIANT = '' # '', 'b', 'c', 'd', ...
TEST_EXPECTED_ANSWERS = {
config.EXPECTED_ANSWERS = (483, 874)
config.TEST_CASES = {
'': (2, 4),
'b': (None, None),
'c': (None, None),
}

DEBUGGING = False
# DEBUGGING = True


def debug(*args):
if DEBUGGING:
print(*args)
else:
pass


def main():
input_config = InputConfig(
as_integers=False,
as_comma_separated_integers=False,
as_json=False,
as_groups=False,
as_oneline=False,
as_coordinates=False,
coordinate_delimeter=None,
as_table=False,
row_func=None,
cell_func=None,
)

if TEST_MODE:
input_filename = f'{PROBLEM_NUM}{TEST_VARIANT}.test.in'
expected_answers = TEST_EXPECTED_ANSWERS[TEST_VARIANT]
else:
input_filename = f'{PROBLEM_NUM}.in'
expected_answers = EXPECTED_ANSWERS

solution = Solution(input_filename, input_config, expected_answers)

solution.solve()
solution.report()


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

Expand Down
8 changes: 0 additions & 8 deletions adventofcode/2022/05.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# Python Standard Library Imports
import copy
import math
import pathlib
import re
import typing as T
from collections import defaultdict
Expand Down Expand Up @@ -34,11 +31,6 @@
config.INPUT_CONFIG.cell_func = None


config.YEAR = int(pathlib.Path.cwd().parts[-1])
config.DAY = int(pathlib.Path(__file__).stem)
config.PROBLEM_NUM = str(config.DAY).zfill(2)


@solution
class Solution(BaseSolution):
def process_data(self):
Expand Down
Loading

0 comments on commit 6d20636

Please sign in to comment.