码迷,mamicode.com
首页 > 其他好文 > 详细

Code Signal_练习题_chessBoardCellColor

时间:2018-08-13 20:48:17      阅读:173      评论:0      收藏:0      [点我收藏+]

标签: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 be
    chessBoardCellColor(cell1, cell2) = true.

    技术分享图片

  • For cell1 = "A1" and cell2 = "H3", the output should be
    chessBoardCellColor(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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!