-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
57 lines (41 loc) · 1.14 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
import sys
from typing import IO, Any
import part01, part02
BOARD_SIZE = 5
def main():
if len(sys.argv) != 3:
print("incorrect number of arguments")
return
_, part, input_file_path = sys.argv
input_data = read_input_data(input_file_path)
if input_data is None:
print("failed to parse input")
return
if part == "part01":
part01.run(input_data)
elif part == "part02":
part02.run(input_data)
else:
print("unrecognized part")
def read_input_data(file_path):
with open(file_path, "r") as file:
chosen_nums = [int(n) for n in file.readline().split(",")]
file.readline()
boards = []
while True:
board = read_board(file)
if board is None:
break
boards.append(board)
return chosen_nums, boards
def read_board(file: IO[Any]):
board = []
for i in range(BOARD_SIZE):
line = file.readline()
if not line:
return None
board.append([int(n) for n in line.split()])
file.readline()
return board
if __name__ == '__main__':
main()