This repository was archived by the owner on Dec 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnail.py
More file actions
49 lines (38 loc) · 1.37 KB
/
Copy pathSnail.py
File metadata and controls
49 lines (38 loc) · 1.37 KB
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
def snail(array):
output_array = []
left, right, up, down = 0, 0, 0, 0
height, width = len(array), len(array[0])
flag = True
position = 0
while flag == True:
if (left + right) > (width-1) or (up + down) > (height-1):
flag = False
position = left
while position < (width - right):
output_array.append(array[up][position])
position += 1
up += 1
if (left + right) > (width-1) or (up + down) > (height-1):
flag = False
position = up
while position < (height - down):
output_array.append(array[position][(width-1)-right])
position += 1
right += 1
if (left + right) > (width-1) or (up + down) > (height-1):
flag = False
position = (width-1) - right
while position >= left:
output_array.append(array[(height-1) - down][position])
position -= 1
down += 1
if (left + right) > (width-1) or (up + down) > (height-1):
flag = False
position = (height-1) - down
while position > up-1:
output_array.append(array[position][left])
print "position = ",
print position
position -= 1
left += 1
return output_array