0
(x +1) +1) + 1)
i have this task: can the bishop (chess) go from place x zu place y i want to say the program add + 0 or + 1 or + 1 + 1 and so on... is there a function in python i can use like this? I want to solve this problem with if, elif, else
5 Respostas
+ 1
Think about the problem like this:
Say you are on (7,1) and want to go to (4,4).
How many steps do you have to take in the x direction? How many in the y direction? Are they the same number of steps? If yes the bishop can go.
You don't need to add +1 over and over - simple addition and subtraction should be enough to get an answer.
+ 1
thanks for the help :) in the moment I have:
https://code.sololearn.com/cEoLwAT38JR2/#py
but for the example 1,8 and 8,1 I get the output of NO and I can't understand why. Any ideas?
0
I found the problem, it was a problem with the indentation. it can not be on the same time that a field is black and white.
here is my final code:
# bishop move
x1 = int(input())
y1 = int(input())
x2 = int(input())
y2 = int(input())
if (x1 + y1) % 2 == 0:
if (x2 + y2) % 2 == 0:
if abs(x2 - x1) == abs(y2 - y1):
print("YES")
else:
print("NO")
else:
print("NO")
elif (x1 + y1) % 2 == 1:
if (x2 + y2) % 2 == 1:
if abs(x2 - x1) == abs(y2 - y1):
print("YES")
else:
print("NO")
else:
print("NO")
else:
print("NO")
0
Oh sorry, I missed your reply.
It's a lot easier than that! The `if abs(x2 - x1) == abs(y2 - y1)` check should be enough.