-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
105 lines (84 loc) · 2.83 KB
/
main.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from termcolor import colored
from time import process_time
import sys
from solutions import day_01, day_02, day_03, day_04, day_05, day_06, day_07, \
day_08, day_09, day_10, day_11, day_12, day_13, day_14, day_15, day_16, \
day_17, day_18, day_19, day_20, day_21, day_22, day_23, day_24, day_25
total_time = 0
YEAR = 2022
NAMES = (
"Calorie Counting",
"Rock Paper Scissors",
"Rucksack Reorganization",
"Camp Cleanup",
"Supply Stacks",
"Tuning Trouble",
"No Space Left On Device",
"Treetop Tree House",
"Rope Bridge",
"Cathode-Ray Tube",
"Monkey in the Middle",
"Hill Climbing Algorithm",
"Distress Signal",
"Regolith Reservoir",
"Beacon Exclusion Zone",
"Proboscidea Volcanium",
"Pyroclastic Flow",
"Boiling Boulders",
"Not Enough Minerals",
"Grove Positioning System",
"Monkey Math",
"Monkey Map",
"Unstable Diffusion",
"Blizzard Basin",
"Full of Hot Air",
)
def test(day):
try:
eval(f"day_{day:02d}.test()")
return colored("PASS", "green")
except AssertionError:
return colored("FAIL", "red")
def solve(day, part):
data = open(f"../inputs/{YEAR}/{day:02d}.txt").read().rstrip()
start_time = process_time()
answer = eval(f"day_{day:02d}.part_{part}")(data)
end_time = process_time()
global total_time
total_time += end_time - start_time
return answer, end_time - start_time
def run(day):
time1, time2 = 0, 0
print(f"Day {day}: {NAMES[day-1]} ({test(day)})")
answer, time1 = solve(day, 1)
print(f" Part 1: {colored(answer, 'cyan')}")
if day != 25:
answer, time2 = solve(day, 2)
print(f" Part 2: {colored(answer, 'cyan')}")
time_str_1 = colored(f"{time1*1000:.3f}", "magenta")
time_str_2 = colored(f"{time2*1000:.3f}", "magenta")
time_str = colored(f"{(time1+time2)*1000:.3f} ms", "magenta")
print(f" ({time_str})" + (f" [{time_str_1} / {time_str_2}]" if day != 25 else "") + "\n")
def main():
if len(sys.argv) == 1:
for day in range(len(NAMES)):
run(day+1)
elif len(sys.argv) == 2 and sys.argv[1].isdigit():
if (day := int(sys.argv[1])) <= len(NAMES):
run(day)
else:
print(colored(f"Day {day} does not exist{' yet' if day <= 25 else ''}.\n", "red"))
elif sys.argv[1] in ("-s", "--skip"):
days = [int(day) for day in sys.argv[2:] if day.isdigit()]
for day in range(len(NAMES)):
if day+1 not in days:
run(day+1)
else:
print(colored("Invalid arguments.\n", "red"))
time_str = colored(f"{total_time:.3f}", "magenta")
avg_time_str = colored(f"{total_time/len(NAMES):.3f}", "magenta")
print(f"Time:")
print(f" sum: {time_str} seconds")
print(f" avg: {avg_time_str} seconds")
if __name__ == "__main__":
main()