Problem 46120. Solve the Challenger puzzle

The Challenger puzzle by Linus Maurer requires the solver to fill a 4x4 matrix of integers from 1 to 9 to match the given sums of the rows, columns, main diagonal, and anti-diagonal. Four of the numbers are given. Numbers can be repeated, and the solution is not necessarily unique.
Write a function to solve the Challenger. The input will be a matrix resembling the game board. For example, if the input is
NaN NaN NaN NaN 12
0 0 0 4 23
0 1 0 0 11
6 0 0 0 21
0 0 2 0 13
9 20 22 17 12
then the sums of the four columns are 9, 20, 22, and 17. The sums of the rows are 23, 11, 21, and 13, and the sums of the two diagonals are 12 and 12. The four starting numbers are 6, 1, 2, and 4, and zeros indicate the numbers to be determined. Ignore the NaNs. The output of the function should be the 4x4 matrix of numbers. In the example, a valid solution would be
1 9 9 4
1 1 4 5
6 3 7 5
1 7 2 3

Solution Stats

18.75% Correct | 81.25% Incorrect
Last Solution submitted on Aug 09, 2024

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers15

Suggested Problems

More from this Author278

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!