Objectives
- Create a two dimensional array
- Process a two dimensional array
- Optimize program execution time by analyzing and improving the algorithm used
This assignment involves writing a program to find all 4 by 4 arrays which contain the numbers from 1 through 16 which also have the property that all rows, all columns, and both diagonals add up to the same value. This involves the use of a two-dimensional array.
It turns out that we can tell what that sum is ahead of time. Since all the numbers from 1 through 16 are represented once, we know that all four rows (or columns) will have to add up to the total of the digits 1 through 16, which is 136. Since all the rows have to have the same sum, we know that each row must be one-quarter of 136, which is 34. So, all rows must sum to 34. Likewise, all columns must sum to 34. The two diagonals must also sum to 34.
Here is an example:
In the example above, the second row is 14+15+2+3 = 34. The third column is 13+2+12+7 = 34. The diagonals are 1+15+12+6 = 16+2+5+11 = 34. Hopefully, that gives you a pretty good idea of the rules for this assignment.
So, what do you have to do? You have to create a program that will find, count, and optionally display all 7040 solutions.