-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoc.py
executable file
·62 lines (48 loc) · 1.54 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
#!/usr/bin/env python3
from utils import noop, get_puzzle, get_solutions
from time import perf_counter
from argparse import ArgumentParser, FileType
from sys import exit
parser = ArgumentParser()
parser.add_argument("-d", "--day", dest="day")
parser.add_argument("-o", "--override", dest="override", type=FileType("r"))
def maybe_int(value):
return value if value is None else int(value)
def handle_result(day, result):
if result is None:
print(day, "ERROR")
return
a, b = result
print(day + "a", a)
print(day + "b", b)
def main():
args = parser.parse_args()
divider = "-" * 80
print("AOC 2021 Solutions:")
print(divider)
solutions = get_solutions()
index = maybe_int(args.day)
if index is not None:
start = perf_counter()
day = f"Day {index:02}"
puzzle = get_puzzle(index)
if args.override is not None:
puzzle = args.override.read().split("\n")
solution = solutions[index]
handle_result(day, solution(puzzle))
print(f"~ {perf_counter()-start:.05f}s")
print(divider)
exit(0)
#for index, solution in get_solutions().items():
for index in range(len(solutions)):
solution = solutions.get(index)
if solution is None:
continue
start = perf_counter()
day = f"Day {index:02}"
puzzle = get_puzzle(index)
handle_result(day, solution(puzzle))
print(f"~ {perf_counter()-start:.05f}s")
print(divider)
if __name__ == "__main__":
main()