sss
unknown
python
4 years ago
1.7 kB
9
Indexable
# 10 adalah len(is_path)
graph = [[1,2,3],[4,5,6]]
path = [1,4,6]
result = 0
x = [x for x in graph if path[0] in x][0]
startX = graph.index(x)
startY = x.index(path[0])
def findpath(graph, row, column, x, y, path):
print(row,column,x,y,path)
if graph[x][y] == path:
print("Check 0 : true")
tuples = (x,y,1)
return tuples
else:
# 4 path
if (x-1 >= 0):
check = graph[x-1][y] == path
if (check):
tuples = (x-1,y,1)
print("Check 1 : true")
return tuples
print("Check 1 : false")
if (y-1 >= 0):
check = graph[x][y-1] == path
if (check):
tuples = (x,y-1,1)
print("Check 2 : true")
return tuples
print("Check 2 : false")
if (x+1 < row):
check = graph[x+1][y] == path
if (check):
tuples = (x+1,y,1)
print("Check 3 : true")
return tuples
print("Check 3 : false")
if (y+1 < column):
check = graph[x][y+1] == path
if (check):
tuples = (x,y+1,1)
print("Check 4 : true")
return tuples
print("Check 4 : false")
tuples = (x,y,0)
print("Check 5 : false")
return tuples
for x in range(0, len(path)):
column = len(graph[0])
row = len(graph)
tuples = findpath(graph, row, column, startX, startY, path[x])
print(tuples)
if (tuples[2] == 0):
break
startX = tuples[0]
startY = tuples[1]
if (x == len(path)):
result = 1
print(result)Editor is loading...