Program / Task Name:

   Magic Square

Level:

 

 Advanced

Point Value:

 

 13

 

Task Description

The Magic Square is a classic math puzzle.  Given a semi empty 4x4 matrix, you must 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 prob13.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, prob13.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

 

 

   
  (c) 2004 Hewlett-Packard Company