V2 Answers [patched] — 9.1.7 Checkerboard
The "9.1.7 Checkerboard, v2" exercise is a core assignment in the course (specifically the Rainforest version). It follows the "Checkerboard, v1" exercise and is part of a progressive three-part series designed to teach students how to work with 2D lists in Python.
The most efficient way to determine the pattern is to check if the sum of the current row and column index is even or odd using the modulus operator 9.1.7 checkerboard v2 answers
Mastering grid-based algorithms is a major milestone in learning computer science. The assignment is a classic coding challenge found in introductory programming curricula, such as CodeHS. It tests your understanding of nested loops, conditional logic, and grid boundaries. The "9
However, a simpler and more systematic approach to solving this problem is to consider it as arranging (n) distinct objects into (n) distinct rows (or columns) such that no row (or column) gets more than one object. This directly translates to (n!) (n factorial) arrangements, as there are (n) choices for the first position, (n-1) for the second, and so on, down to 1 choice for the last position. The assignment is a classic coding challenge found
The key to this problem is using the modulo operator ( % ) to detect whether a cell should be a 0 or 1.
// Dimensions of the grid var ROWS = 8; var COLS = 8; var TILE_SIZE = 40; function start() for (var r = 0; r < ROWS; r++) for (var c = 0; c < COLS; c++) var x = c * TILE_SIZE; var y = r * TILE_SIZE; var rect = new Rectangle(TILE_SIZE, TILE_SIZE); rect.setPosition(x, y); // Check row + col sum for alternation if ((r + c) % 2 === 0) rect.setColor(Color.BLACK); else rect.setColor(Color.WHITE); add(rect); Use code with caution. 2. Java / Console Matrix Solution