Programming challenge #1

by Charles Bovaird

Diagonal Sums on Spiral Matrices

Challenge - to write a program in any language to solve the following problem:

Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral matrix is formed as follows:

21 22 23 24 25
20  7  8  9 10
19  6  1  2 11
18  5  4  3 12
17 16 15 14 13

It can be verified that the sum of both diagonals is 101. What is the sum of both diagonals in a 1001 by 1001 spiral matrix formed the same way?

a) Create a program that will produce the diagonal sum for the 1001 by 1001 spiral matrix as well as other such matrices. Note: Some analysis would be initially useful.

b) What would be the program to determine all the diagonal sums for the spiral matrices from 1 to 1001?

Solutions should state clearly which language and version has been used and sent to: treasurer@dacs.org

Correct solutions will be recognized in future editions of DACS.DOC.



DacsGear!
Mugs and more, visit CafePress to order
 
 
© Danbury Area Computer Society, Inc. All Rights Reserved.
Web Site Terms & Conditions of Use