aboutsummaryrefslogtreecommitdiff
path: root/challenge-281/sgreen/python/ch-1.py
blob: 293f65177ea4d82f88cb1b68d0da64c600dd685f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python3

import re
import sys


def check_color(coords: str) -> bool:
    '''Determine if a coordinate on a chess board is light'''

    # Check if the position is valid
    if not re.search('^[a-h][1-8]$', coords):
        raise ValueError('Not a valid chess coordinate!')

    if coords[0] in ('a', 'c', 'e', 'g') and int(coords[1]) % 2 == 0:
        return True
    if coords[0] in ('b', 'd', 'f', 'h') and int(coords[1]) % 2 == 1:
        return True
    return False


def main():
    result = check_color(sys.argv[1])
    print('true' if result else 'false')


if __name__ == '__main__':
    main()