9.1.6 Checkerboard V1 Codehs _hot_
CodeHS Exercise 9.1.6 (Checkerboard, v1) requires creating an 8x8 grid, utilizing nested loops to populate top and bottom rows with 1s in alternating positions while leaving middle rows as 0s. The solution initializes a 2D list and applies an assignment statement to update specific cells where the sum of the row and column indices is odd. For detailed code solutions, review the answers at
The Goal
The objective is to create a checkerboard pattern using a 2D array logic concept. You are usually provided with a Rectangle class and a Checkerboard class (which uses Grid). 9.1.6 checkerboard v1 codehs
The 9.1.6 Checkerboard V1 is less about "drawing" and more about coordinate math. Once you master the (row + col) % 2 trick, you can generate patterns for much more complex grid-based games and visualizations. CodeHS Exercise 9
remain all zeros, as these represent the empty "no-man's land" in the middle of a checkers game. Square (0, 0): $0 + 0 = 0$
- Square (0, 0): $0 + 0 = 0$ (Even) $\rightarrow$ Black
- Square (0, 1): $0 + 1 = 1$ (Odd) $\rightarrow$ White
- Square (1, 0): $1 + 0 = 1$ (Odd) $\rightarrow$ White
- Square (1, 1): $1 + 1 = 2$ (Even) $\rightarrow$ Black
The trick to the checkerboard pattern is checking the sum of the indices If the sum is even, the square should be 0.
R B R B R B R B
B R B R B R B R
R B R B R B R B
B R B R B R B R
R B R B R B R B
B R B R B R B R
R B R B R B R B
B R B R B R B R
Extending the Challenge
Once you have mastered 9.1.6 Checkerboard v1, challenge yourself with these modifications:
2. Problem Description
Karel starts at position (1, 1) facing East. The world has variable dimensions (rows and columns). Karel must fill alternating squares with beepers, like a checkerboard.