Ada took a standard chessboard with 8 rows (numbered 1 through 8) and 8 columns (numbered 1 through 8); let's denote a cell in row r and column c by (r,c). Then, Ada placed a bishop in a cell (r0,c0)
; it is guaranteed that this cell is black. Ada's goal is to move the bishop in such a way that it visits all black cells.
Remember that a bishop is a piece that moves diagonally ― formally, the bishop may move from a cell (rs,cs)
to a cell (rt,ct) if and only if either rs+cs=rt+ct or rs−cs=rt−ct. In such a move, the bishop visits all cells between (rs,cs) and (rt,ct)
on this diagonal (inclusive).
Help Ada find a sequence of at most 64
moves for the bishop such that when the bishop follows this route, it visits all black cells on the chessboard. Note that each cell may be visited multiple times and it is not necessary to return to the starting point.
What I have tried:
from collections import deque
moves=[[0 for i in range(8)] for j in range(8)]
count=0
x=[-1,-1,1,1]
y=[-1,1,1,-1]
xq=deque()
yq=deque()
def is_safe(x,y):
return (x>=0 and x<=7 and y>=0 and y<=7)
xq.append(4)
yq.append(5)
while(len(xq)>0):
count+=1
xx=xq.popleft()
yy=yq.popleft()
if count>=128:
break
moves[xx][yy]+=1
for i in range(4):
xx=xx+x[i]
yy=yy+y[i]
if is_safe(xx,yy):
xq.append(xx)
yq.append(yy)
print(moves)
I dont know if I am doing right.How to approach this problem