The Euler Project Problem 28 proposed finding the sum of entries of the diagonals of a spiral center built in one (1) clockwise until you have a 1001X1001 size.
|
| 7X7 Spiral |
An analysis of each of the diagonal terms of organizing low to high regardless of their position within the respective diagonal let us see what following:
|
| main Diagonal |
one (1), each new term corresponds to the sum above a certain value, that value has the property to increase by four each time the index of the term is even, and for the second term is added to 4, which is maintained for the third, but in the fourth term is added to 8, on can use this reasoning to find any term of the main diagonal.
In the secondary diagonal must
Diagonal |
also started one, but this time, each new term corresponding to the previous by adding two more than in the previous table clearly seen which is the reasoning that allows you to find any term of the secondary diagonal.
this analysis, the rest is a couple of programming cycles that include resources for the diagonal of a spiral 1001X1001 (each diagonal will have 1001 entries) and leads to the solution of the Euler Project Problem 28.
0 comments:
Post a Comment