Magic Square
Created on Nov. 8, 2024 by Julien Palard
Implement the fill_magic_square
function.
It takes a single argument: a numpy.array
of integers representing a
partially filled magic
square. Holes are
represented using zeros.
Your fill_magic_square
function will have to find and fill the gaps
in the square.
Do not return a value, just modify the square in-place.
Beware, my magic squares may contain any natural number (> 0
), I do
not restrict myself to magic squares with numbers from 1
to
square_size ** 2
.
Examples
1 2 3 4 5 6 7 8 |
|
Should give:
1 2 3 |
|
An harder one:
1 2 3 4 5 6 7 8 9 |
|
Should give:
1 2 3 4 |
|
Notice how this can always be solved without doing advanced math as
there's always an obvious move to do. So there's always a single valid
solution. I'll never give you np.array([[0, 0, 0], [0, 0, 0], [0, 0,
0]])
, I promise.