Problem #12

Code Wars II
Danger Level: Aggressive Blue




}Magic Square~

Point Value: 7

Problem Statement

A classic math puzzle.  Given a semi empty 4x4 matrix, determine which values to place in each element to match the row, column, and diagonal sums.

                .
|  |  |13|  |  67
| 3|  |  |  |  37
|  |  |  |11|  34
|  |15|  |  |  69

 52 48 31 76   38



Program Input

Each line in the file PROB12.IN gives the values for each row in the magic square.  Blank values that need to be filled in are represented by XX, like this:

 XX XX 13 XX 67
  3 XX XX XX 37
 XX XX XX 11 34
 XX 15 XX XX 69
 52 48 31 76 38
 

Program Output

Determine the missing values and print the entire magic square to the output file, PROB12.OUT.  You may assume all values in the square, including the sums, are within the range 0 to 99, inclusive.

  9 27 13 18 67
  3  1 12 21 37
 16  5  2 11 34
 24 15  4 26 69
 52 48 31 76 38