-
Notifications
You must be signed in to change notification settings - Fork 0
/
aoc.py
75 lines (61 loc) · 2.56 KB
/
aoc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import argparse
import traceback
from code import day1, day2, day3, day4, day5, day6, day7
import tomllib
parser = argparse.ArgumentParser(
prog= 'aoc.py',
description= 'Compute days for Advent of Code'
)
parser.add_argument('-d','--day', type= int, choices= range(1,25))
parser.add_argument('-t', '--test', action='store_true')
parser.add_argument('-p', '--part', type=int, choices=range(1,3))
parser.add_argument('-a', '--all', action='store_true')
args = parser.parse_args()
def compute_day_by_part(x):
if not args.part:
result_part1 = globals()[f"day{x}"].compute(f"input/input_{x}")
result_part2 = globals()[f"day{x}"].compute_2(f"input/input_{x}")
print(f"Jour {x} (p1): {result_part1} \t (p2): {result_part2}")
elif args.part == 1:
result_part1 = globals()[f"day{x}"].compute(f"input/input_{x}")
print(f"Jour {x} (p1): {result_part1}")
else:
result_part2 = globals()[f"day{x}"].compute_2(f"input/input_{x}")
print(f"Jour {x} (p2): {result_part2}")
def compute_day_by_part_test(x):
with open("test.toml", 'rb') as f:
test = tomllib.load(f)
if not args.part:
result_part1 = globals()[f"day{x}"].compute(f"test_input/input_{x}")
check_result_part_1 = "✔" if (result_part1 == test[f"day{x}"]["part1"]) else "✘"
result_part2 = globals()[f"day{x}"].compute_2(f"test_input/input_{x}")
check_result_part_2 = "✔" if (result_part2 == test[f"day{x}"]["part2"]) else "✘"
print(
f"Jour {x} (test) (p1): {result_part1} {check_result_part_1} \t (p2): {result_part2} {check_result_part_2}")
elif args.part == 1:
result_part1 = globals()[f"day{x}"].compute(f"test_input/input_{x}")
check_result_part_1 = "✔" if (result_part1 == test[f"day{x}"]["part1"]) else "✘"
print(f"Jour {x} (test) (p1): {result_part1} {check_result_part_1}")
else:
result_part2 = globals()[f"day{x}"].compute_2(f"test_input/input_{x}")
check_result_part_2 = "✔" if (result_part2 == test[f"day{x}"]["part2"]) else "✘"
print(f"Jour {x} (test) (p2): {result_part2} {check_result_part_2}")
def compute_day(x):
try:
if not args.test:
compute_day_by_part(x)
else:
compute_day_by_part_test(x)
except KeyError as Error:
if not args.all:
print("This day is not yet implemented.")
print(traceback.format_exc())
return False
else:
return True
if not args.all:
compute_day(args.day)
else:
i = 1
while compute_day(i):
i += 1