-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswea_1210.py
More file actions
38 lines (30 loc) · 888 Bytes
/
Copy pathswea_1210.py
File metadata and controls
38 lines (30 loc) · 888 Bytes
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
test = [
[1, 0, 0, 0, 1, 0, 1, 0, 0, 1],
[1, 0, 0, 0, 1, 0, 1, 1, 1, 1],
[1, 0, 0, 0, 1, 0, 1, 0, 0, 1],
[1, 0, 0, 0, 1, 1, 1, 0, 0, 1],
[1, 0, 0, 0, 1, 0, 1, 0, 0, 1],
[1, 1, 1, 1, 1, 0, 1, 1, 1, 1],
[1, 0, 0, 0, 1, 0, 1, 0, 0, 1],
[1, 1, 1, 1, 1, 0, 1, 0, 0, 1],
[1, 0, 0, 0, 1, 1, 1, 0, 0, 1],
[1, 0, 0, 0, 1, 0, 1, 0, 0, 2]
]
def finding_start(matrix):
for j in range(10):
if matrix[-1][j] == 2:
start = j
return start
def finding_road(matrix):
start = finding_start(matrix)
left = -1
right = 1
for i in range(10 - 1, -1, -1):
if matrix[i][start + left] == 1 and start + left > 0:
start += left
elif matrix[i][start + right] == 1 and start + right < 9:
start += right
if i == 0:
end = start
return end
print(finding_road(test))