-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrack_8_2.py
37 lines (33 loc) · 1.38 KB
/
crack_8_2.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
def move(start_x, start_y, end_x, end_y):
global COUNT
if start_x == end_x and start_y == end_y:
COUNT += 1
elif start_x <= end_x and start_y <= end_y:
move(start_x+1, start_y, end_x, end_y)
move(start_x, start_y+1, end_x, end_y)
def move_path(start_x, start_y, end_x, end_y, path):
if start_x == end_x and start_y == end_y:
path.append((start_x, start_y))
print path
elif start_x <= end_x and start_y <= end_y:
path.append((start_x, start_y))
path1, path2 = path[:], path[:]
move_path(start_x+1, start_y, end_x, end_y, path1)
move_path(start_x, start_y+1, end_x, end_y, path2)
def move_disable_path(start_x, start_y, end_x, end_y, disable_x, disable_y, path):
if start_x == end_x and start_y == end_y:
path.append((start_x, start_y))
print path
elif start_x <= end_x and start_y <= end_y:
if start_x != disable_x or start_y != disable_y:
path.append((start_x, start_y))
path1, path2 = path[:], path[:]
move_disable_path(start_x+1, start_y, end_x, end_y, disable_x, disable_y, path1)
move_disable_path(start_x, start_y+1, end_x, end_y, disable_x, disable_y, path2)
if __name__ == '__main__':
COUNT = 0
move(0, 0, 2, 2)
print COUNT
move_path(0,0,2,2,[])
print '-'*10
move_disable_path(0,0,2,2,1,1,[])