-
Notifications
You must be signed in to change notification settings - Fork 0
/
parsers.py
59 lines (42 loc) · 1.55 KB
/
parsers.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
from solver import solve
def get_data(file_name):
with open(file_name, "r") as f:
# data = file.readline().strip('\n')
C, R, S = tuple(map(int, f.readline().strip("\n").split()))
print(R, C, S)
snake_lenghts = list(map(int, f.readline().strip("\n").split()))
matrix = [
list(map(notasterisk, f.readline().strip("\n").split())) for _ in range(R)
]
# print(matrix)
return R, C, S, snake_lenghts, matrix
def notasterisk(x):
if x != "*":
return int(x)
# return '*'
return -999999
def save_data(file, data):
with open(file, "w") as f:
f.write(data)
def main():
files = ["inputs/00-example.txt",
# "inputs/01-chilling-cat.txt",
# "inputs/02-swarming-ant.txt",
# "inputs/03-input-anti-greedy.txt",
# "inputs/04-input-low-points.txt",
# "inputs/05-input-opposite-points-holes.txt",
"inputs/06-input-reply-running-man.txt"]
for file_name in files:
R, C, S, snake_lenghts, matrix = get_data(file_name)
start_pos, moves = solve(R, C, S, snake_lenghts, matrix)
data = ""
for snake_pos, snake_moves in zip(start_pos, moves):
# print(snake_moves)
if not snake_moves:
data += '\n'
continue
# print(snake_moves)
data += f"{snake_pos[1]} {snake_pos[0]} {' '.join(snake_moves)}\n"
save_data(f"outputs/{file_name.split('/')[1]}", data)
if __name__ == "__main__":
main()