Last active
March 20, 2019 06:44
-
-
Save OzuYatamutsu/f763e54eb4e1a7537707a309a388c587 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def chessBoardCellColor(cell1: str, cell2: str) -> bool: | |
""" | |
Given two cells on the standard chess board, | |
determines whether they have the same color or not. | |
""" | |
def _get_color(cell: str) -> str: | |
# Cells are a letter and a number. | |
# If letter is even index, blacks = even, whites = odd. | |
# If letter is odd index, blacks = odd, whites = even. | |
return { | |
0: 'black' if int(cell[1]) % 2 == 0 else 'white', | |
1: 'white' if int(cell[1]) % 2 == 0 else 'black' | |
}[(ord(cell[0]) - ord('A')) % 2] | |
return _get_color(cell1) == _get_color(cell2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment