-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP1_Start_Finish.py
72 lines (52 loc) · 1.8 KB
/
P1_Start_Finish.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
61
62
63
64
65
66
67
68
69
70
71
72
# Problem [Start_Finish]:
# 1. There is a Maze[n*m Matrix]
# 2. There are two poins inside the Maze, one is START and one is FINISH
# 3. Take matrix size as input and take co-ordinates from users as START and FINISH, for example (1,1) for taking first element as START and (n,m) for taking last element as START, same goes for FINISH.
# 4. Calculate number of ways by which one can travel from element to element to reach the FINISH point, starting from START, but one can't travel back to the same element which he had already traveled inside his START-FINISH journey.
# Example
# Input:
# 2 3 # Maze Size (n*m)
# 1,1 # START
# 2,3 # FINISH
# Output:
# 4 # Number of ways to travel from START to FINISH without forming loop.
# Explaination:
# Matrix:
# *(S) * *
# * * *(F)
# Total number of ways to go from S to F are 4.
#Solution
# INPUTS
row,column = input(": ").split(" ")
startX, startY = input("Start: ").split(",")
finishX, finishY = input("Finish: ").split(",")
row = int(row)
column = int(column)
startX = int(startX)-1
startY = int(startY)-1
finishX = int(finishX)-1
finishY = int(finishY)-1
# Maze Formation
matrix_array = [["*" for i in range(column)] for i in range(row)]
print("")
matrix_array[startX][startY] = "S"
matrix_array[finishX][finishY] = "F"
# Printing Maze with Start and FINISH on it
for i in range(row):
for j in range(column):
print (matrix_array[i][j],end=" ")
print("\n")
def checkSideElement(x,y):
temp_array1=[]
for i in ((x,y-1),(x-1,y),(x+1,y),(x,y+1)):
try:
if i[0] < 0 or i[1] < 0:
pass
else:
if matrix_array[i[0]][i[1]]:
temp_array1.append(i)
except:
pass
return temp_array1
# print (checkSideElement(1,2))
# to be continued