@@ -18,10 +18,10 @@ def solve_maze(
18
18
- destination_column (int): The column index of the destination point.
19
19
Returns:
20
20
- solution (list[list[int]]): A 2D matrix representing the solution path
21
- ... if it exists.
21
+ if it exists.
22
22
Raises:
23
- - ValueError: If no solution exists or if the source or\
24
- destination coordinates are invalid.
23
+ - ValueError: If no solution exists or if the source or
24
+ destination coordinates are invalid.
25
25
Description:
26
26
This method navigates through a maze represented as an n by n matrix,
27
27
starting from a specified source cell and
@@ -35,8 +35,11 @@ def solve_maze(
35
35
... [0, 0, 1, 0, 0],
36
36
... [1, 0, 0, 1, 0]]
37
37
>>> solve_maze(maze,0,0,len(maze)-1,len(maze)-1)
38
- [[0, 1, 1, 1, 1], [0, 0, 0, 0, 1], [1, 1, 1, 0, 1],\
39
- [1, 1, 1, 0, 0], [1, 1, 1, 1, 0]]
38
+ [[0, 1, 1, 1, 1],
39
+ [0, 0, 0, 0, 1],
40
+ [1, 1, 1, 0, 1],
41
+ [1, 1, 1, 0, 0],
42
+ [1, 1, 1, 1, 0]]
40
43
41
44
Note:
42
45
In the output maze, the zeros (0s) represent one of the possible
@@ -48,20 +51,27 @@ def solve_maze(
48
51
... [0, 0, 0, 0, 0],
49
52
... [0, 0, 0, 0, 0]]
50
53
>>> solve_maze(maze,0,0,len(maze)-1,len(maze)-1)
51
- [[0, 1, 1, 1, 1], [0, 1, 1, 1, 1], [0, 1, 1, 1, 1],\
52
- [0, 1, 1, 1, 1], [0, 0, 0, 0, 0]]
54
+ [[0, 1, 1, 1, 1],
55
+ [0, 1, 1, 1, 1],
56
+ [0, 1, 1, 1, 1],
57
+ [0, 1, 1, 1, 1],
58
+ [0, 0, 0, 0, 0]]
53
59
54
60
>>> maze = [[0, 0, 0],
55
61
... [0, 1, 0],
56
62
... [1, 0, 0]]
57
63
>>> solve_maze(maze,0,0,len(maze)-1,len(maze)-1)
58
- [[0, 0, 0], [1, 1, 0], [1, 1, 0]]
64
+ [[0, 0, 0],
65
+ [1, 1, 0],
66
+ [1, 1, 0]]
59
67
60
68
>>> maze = [[1, 0, 0],
61
69
... [0, 1, 0],
62
70
... [1, 0, 0]]
63
71
>>> solve_maze(maze,0,1,len(maze)-1,len(maze)-1)
64
- [[1, 0, 0], [1, 1, 0], [1, 1, 0]]
72
+ [[1, 0, 0],
73
+ [1, 1, 0],
74
+ [1, 1, 0]]
65
75
66
76
>>> maze = [[1, 1, 0, 0, 1, 0, 0, 1],
67
77
... [1, 0, 1, 0, 0, 1, 1, 1],
@@ -72,9 +82,14 @@ def solve_maze(
72
82
... [0, 1, 0, 1, 0, 1, 1, 1],
73
83
... [1, 1, 0, 0, 0, 0, 0, 1]]
74
84
>>> solve_maze(maze,0,2,len(maze)-1,2)
75
- [[1, 1, 0, 0, 1, 1, 1, 1], [1, 1, 1, 0, 0, 1, 1, 1], [1, 1, 1, 1, 0, 1, 1, 1],\
76
- [1, 1, 1, 0, 0, 1, 1, 1], [1, 1, 0, 0, 1, 1, 1, 1], [1, 1, 0, 1, 1, 1, 1, 1],\
77
- [1, 1, 0, 1, 1, 1, 1, 1], [1, 1, 0, 1, 1, 1, 1, 1]]
85
+ [[1, 1, 0, 0, 1, 1, 1, 1],
86
+ [1, 1, 1, 0, 0, 1, 1, 1],
87
+ [1, 1, 1, 1, 0, 1, 1, 1],
88
+ [1, 1, 1, 0, 0, 1, 1, 1],
89
+ [1, 1, 0, 0, 1, 1, 1, 1],
90
+ [1, 1, 0, 1, 1, 1, 1, 1],
91
+ [1, 1, 0, 1, 1, 1, 1, 1],
92
+ [1, 1, 0, 1, 1, 1, 1, 1]]
78
93
>>> maze = [[1, 0, 0],
79
94
... [0, 1, 1],
80
95
... [1, 0, 1]]
@@ -98,7 +113,7 @@ def solve_maze(
98
113
ValueError: Invalid source or destination coordinates
99
114
100
115
>>> maze = [[1, 0, 0],
101
- ... [0, 1, 1 ],
116
+ ... [0, 1, 0 ],
102
117
... [1, 0, 0]]
103
118
>>> solve_maze(maze,0,1,len(maze),len(maze)-1)
104
119
Traceback (most recent call last):
@@ -180,4 +195,4 @@ def run_maze(
180
195
if __name__ == "__main__" :
181
196
import doctest
182
197
183
- doctest .testmod ()
198
+ doctest .testmod (optionflags = doctest . NORMALIZE_WHITESPACE )
0 commit comments