Laser bombs inp lists split for in inp split field for in range int li

 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
# Laser bombs
inp = '''5 4
2 3
0 2
1 4
2 0'''
lists = [i.split(' ') for i in inp.split('\n')]
field = [ [0 for k in range(int(lists[0][0]))] for j in range(int(lists[0][0]))]
for attack in range(int(lists[0][1])):
for position in range(int(lists[0][0])):
field[int(lists[attack + 1][0])][position] += 1
if position != int(lists[attack + 1][0]):
field[position][int(lists[attack + 1][1])] += 1
for result in field:
for value in result:
print(value, end = ' ')
print()
# To rotate an image
image = [
[ 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]
]
def rotate(matrix):
temp = None
size = 0
for i in matrix:
size += 1
for x in range(size // 2 + 1): # перебір по концентричних квадратах
y = x
for position in range(size - 1 - 2 * x): # перебір по стороні квадрата
for switch in range(5): # поворот через тимчасове значення по всіх сторонах
matrix[y][x], temp = temp, matrix[y][x]
x, y = size - 1 - y, x
x, y = y + 1, x
rotate(image)
for line in image:
print(line)