Skip to content

Instantly share code, notes, and snippets.

@OzuYatamutsu
Last active March 20, 2019 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OzuYatamutsu/f763e54eb4e1a7537707a309a388c587 to your computer and use it in GitHub Desktop.
Save OzuYatamutsu/f763e54eb4e1a7537707a309a388c587 to your computer and use it in GitHub Desktop.
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