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

18th May 2020, 3:44 PM
Sur Tur
Sur Tur - avatar
4 Antworten
+ 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.
18th May 2020, 9:38 PM
Schindlabua
Schindlabua - avatar
+ 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?
20th May 2020, 1:10 PM
Sur Tur
Sur Tur - avatar
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")
28th May 2020, 4:01 PM
Sur Tur
Sur Tur - avatar
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.
28th May 2020, 5:53 PM
Schindlabua
Schindlabua - avatar