← Back to challenges

The Magic Square Game

PythonHardalgorithmsmathvalidationgames

Instructions

There are two players, Alice and Bob, each with a 3-by-3 grid. A referee tells Alice to fill out one particular row in the grid (say the second row) by putting either a 1 or a 0 in each box, such that the sum of the numbers in that row is odd. The referee tells Bob to fill out one column in the grid (say the first column) by putting either a 1 or a 0 in each box, such that the sum of the numbers in that column is even.

Alice and Bob win the game if Alice’s numbers give an odd sum, Bob’s give an even sum, and (most important) they’ve each written down the same number in the one square where their row and column intersect.

Examples

magic_square_game([2, "100"], [1, "101"]) ➞ False

magic_square_game([2, "001"], [1, "101"]) ➞ True

magic_square_game([3, "111"], [2, "011"]) ➞ True

magic_square_game([1, "010"], [3, "101"]) ➞ False

# Two lists, Alice [row, "her choice"], Bob [column, "his choice"]

Notes

  • The row of Alice is always odd, the column of Bob is always even.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.