Determine Color of a Chessboard Square - Problem
Imagine you're developing a chess game and need to determine the color of any square on the chessboard. You are given a coordinate string that represents a square on a standard 8ร8 chessboard.
A chessboard follows a specific pattern where squares alternate between white and black colors. The bottom-left square (a1) is always a dark square, and colors alternate from there.
Your task: Given coordinates like "a1", "c7", or "h8", return true if the square is white, and false if it's black.
The coordinate format is always: letter first (a-h representing columns), then number second (1-8 representing rows).
Input & Output
example_1.py โ Basic White Square
$
Input:
coordinates = "a1"
โบ
Output:
false
๐ก Note:
Square a1 is black. Using the mathematical approach: a=1, row=1, sum=1+1=2 (even), so it's black.
example_2.py โ Basic Black Square
$
Input:
coordinates = "h3"
โบ
Output:
false
๐ก Note:
Square h3 is black. Using the formula: h=8, row=3, sum=8+3=11 (odd), so it should be white... Wait, let me recalculate based on the actual chessboard pattern.
example_3.py โ Corner Case
$
Input:
coordinates = "c7"
โบ
Output:
true
๐ก Note:
Square c7 is white. Using our formula: c=3, row=7, sum=3+7=10 (even). Since a1 is black and we want even sums to be white, we need to adjust our logic.
Constraints
-
coordinates.length == 2 -
coordinates[0]is a letter from'a'to'h' -
coordinates[1]is a digit from'1'to'8' - The coordinate will always represent a valid chessboard square
Visualization
Tap to expand
Understanding the Visualization
1
Observe the Pattern
Notice that colors alternate in both directions
2
Find the Formula
Realize that coordinate sum parity determines color
3
Apply Mathematics
Use modular arithmetic to get instant results
Key Takeaway
๐ฏ Key Insight: Chessboard colors follow a beautiful mathematical pattern - the sum of coordinate numbers determines the color through simple parity checking!
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code