9.1.7 Checkerboard V2 Answers
CodeHS 9.1.7 Checkerboard v2 exercise, the goal is to create a function that generates a 2D list (a list of lists) representing an 8x8 checkerboard pattern using 0s and 1s. Solution Code # Create an empty list for the current row current_row
public void run() // Create an ArrayList of ArrayLists (2D ArrayList) ArrayList<ArrayList<Color>> board = new ArrayList<>();- Parity (even/odd) creates alternating patterns in both directions.
- Adding row and column indices ensures that moving one step in either direction flips the parity → alternates color.
Nested Loops: The outer loop (i) iterates through the 8 rows, while the inner loop (j) iterates through the 8 columns for each row. 9.1.7 checkerboard v2 answers
If you share the specific language/framework (Python + turtle, Java + Swing, JavaScript + p5.js, etc.), I can explain the exact logic or help debug your code. CodeHS 9
private static final int ROWS = 8;
private static final int COLS = 8;
private static final int SQUARE_SIZE = 50;
Short Answer (Java):
def print_checkerboard(size): for i in range(size): # Create an empty string for each row row_str = "" for j in range(size): # If the sum of the row index (i) and column index (j) is even, use 0 # Otherwise, use 1 (this creates the alternating pattern) if (i + j) % 2 == 0: row_str += "0 " else: row_str += "1 " print(row_str) # Example call for an 8x8 board print_checkerboard(8) Use code with caution. Copied to clipboard Explanation of the Logic Nested Loops : The outer loop ( i
