Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum ChessColor {
- case black
- case white
- }
- func chessBoard(x: String, y: Int) -> ChessColor? {
- guard x.count == 1,
- let index = "abcdefgh".range(of: x)?.lowerBound.encodedOffset else {
- return nil
- }
- return (index + y) % 2 == 0 ? .white : .black
- }
Advertisement
Add Comment
Please, Sign In to add comment