-
Notifications
You must be signed in to change notification settings - Fork 2
/
sample tests.py
61 lines (54 loc) · 1.62 KB
/
sample tests.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
def movement(matrix, x, y, visited=[[]], right=True, down=True):
visited = visited
if(x == len(matrix)-1 and y == len(matrix[0])-1 and matrix[x][y] == 1):
return True
if(matrix[x][y] == 0):
return False
if(y == len(matrix[0])-1) and right:
right = False
if x == len(matrix)-1 and down:
down = False
visited[-1].append("R")
if right and movement(matrix, x, y+1, visited):
temp = ''.join(visited[-1])
tally.append(temp)
visited.append([])
# for i in range(len(visited)):
# visited.pop()
elif visited[-1] != [] and visited[-1][-1] == "R":
visited[-1].pop()
visited[-1].append("D")
if down and movement(matrix, x+1, y, visited):
temp = ''.join(visited[-1])
tally.append(temp)
visited.append([])
# for i in range(len(visited)):
# visited.pop()
elif visited[-1] != [] and visited[-1][-1] == "D":
visited[-1].pop()
# if(x == 0 and y == 0):
# return visited
r = int(input())
# row count input
matrix = []
for i in range(r):
matrix.append(list(map(int, input().split())))
# matrix = [[1, 1, 1, 1],
# [1, 1, 1, 1],
# [1, 1, 1, 1]]
# matrix = [[1, 0, 0, 0],
# [1, 1, 0, 1],
# [1, 1, 0, 0],
# [0, 1, 1, 1]]
tally = []
movement(matrix, 0, 0)
initial = tally[0]
for i in range(len(tally)):
if tally[i] == initial:
print(tally[i] + "R")
else:
temp = initial[:abs(len(tally[i])-len(tally[0]))]
if(temp == ''):
initial = tally[i]
temp += tally[i]
print(temp + "R")