标签:nbsp alt pen code signal rmi show com display
Given two cells on the standard chess board, determine whether they have the same color or not.
Example
For cell1 = "A1"
and cell2 = "C3"
, the output should bechessBoardCellColor(cell1, cell2) = true
.
For cell1 = "A1"
and cell2 = "H3"
, the output should bechessBoardCellColor(cell1, cell2) = false
.
我的解答:
def chessBoardCellColor(cell1, cell2): return abs(int(cell1[1])-int(cell2[1])) % 2 == 0 if abs(ord(cell1[0]) - ord(cell2[0])) % 2 == 0 else abs(int(cell1[1])-int(cell2[1])) % 2 == 1
def chessBoardCellColor(cell1, cell2): return (ord(cell1[0]) + int(cell1[1]) + ord(cell2[0]) + int(cell2[1])) % 2 == 0
Code Signal_练习题_chessBoardCellColor
标签:nbsp alt pen code signal rmi show com display
原文地址:https://www.cnblogs.com/YD2018/p/9470514.html