-2 -1 -1 -2 -1 -2 -2 -1 def Print for in range len -2 for k2 in range

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
b = [[-2,1],[-1,2],[1,2],[2,1],[2,-1],[1,-2],[-1,-2],[-2,-1]]
def Print(a):
for k in range(2,len(a)-2):
for k2 in range(2,len(a[k])-2):
print("%4d"%a[k][k2],end = '')
print()
print("Введите длину и ширину поля")
x,y = map(int,input().split())
print("Введите координаты места нахождения коня")
i,j = map(int,input().split());i += 1;j += 1
a = [[-1]*(y+4)]*2 + [[-1]*2+[0]*y+[-1]*2 for k in range(x)] + [[-1]*(y+4)]*2
d = 1;t = 0;a[0][0] = 1
def move(a,i,j,d):
if a[i][j] != 0: return
else:
a[i][j] = d
if d == x*y:a[0][0] = 0;Print(a);return
else:
for k in range(8):
move(a,i+b[k][0],j+b[k][1],d+1)
a[i][j] = 0
move(a,i,j,d)
if a[0][0] == 1:print("Невозможно пройти все поле")