-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonExample1.py
More file actions
57 lines (41 loc) · 1006 Bytes
/
pythonExample1.py
File metadata and controls
57 lines (41 loc) · 1006 Bytes
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
#!/usr/bin/env python3
# matrix=[ [1,2,3], [4,5,6], [7,8,9] ]
a=5
matrix = [ list(range(i*a+1, (i+1)*a+1)) for i in range(a) ]
factor =len(matrix)**2
top_is =0
left_is =0
right_is =len(matrix)-1
bottom_is =len(matrix)-1
top =len(matrix)
right =len(matrix)
bottom =len(matrix)-2
left =len(matrix)-2
z =[]
while factor>0:
print(f'FACTOR BEGIN:={factor}')
for i in range(top):
z.append(matrix[top_is][i])
factor-=1
top-=1
top_is+=1
print(f'Z:= {z}')
for i in range(1,right):
z.append(matrix[i][right_is])
factor-=1
right_is-=1
right-=1
print(f'Z:= {z}')
for i in range(bottom,-1,-1):
z.append(matrix[bottom_is][i])
factor-=1
bottom-=1
bottom_is-=1
print(f'Z:= {z}')
for i in range(left,left_is,-1):
z.append(matrix[i][left_is])
factor-=1
left_is+=1
bottom_is=top_is
print(f'FACTOR END:={factor}')
print(z)