Sum of Diagonals in 1001x1001 Spiral

  • Thread starter Thread starter AntonVrba
  • Start date Start date
  • Tags Tags
    Sum
AI Thread Summary
The discussion focuses on calculating the sum of the diagonals in a spiral matrix, specifically for a 1001 by 1001 grid. The sum of the diagonals for an n x n spiral, where n is odd, is given by the formula (2/3)n^3 + (1/2)n^2 + (4/3)n - 3/2. For n=1001, this results in a total of 669171001. A participant shared a Java program that computes the same sum, confirming the formula's accuracy. The conversation also touches on the origins of the formula, with acknowledgments of previous contributions and a reference to Galileo's work. The exchange highlights the collaborative nature of mathematical discovery and the importance of proper citation in academic discussions.
AntonVrba
Messages
92
Reaction score
0
Consider a spiral starting with the number 1 and moving to the right in a clockwise direction, below is an example of a 5 by 5 spiral and the diagonal is highlighted:


21 22 23 24 25
20 07 08 09 10
19 06 01 02 11
18 05 04 03 12
17 16 15 14 13

The sum of both diagonals is 101.

if the spiral formed in the same way to 1001 by 1001, then what is the sum of both diagonals?
 
Physics news on Phys.org
HINT:

the number in the top right corner is n^2, the other corners are given by: n^2-n+1, n^2-2n+2, and n^2-3n+3.
 
Answer:


Argh, my stupid computer crashed while I finished typing out the solution here.
Luckily my closed form formula was still copied to mthe memory:
Sum of diagonals for the nxn spiral (n is odd): (2/3)n^3+(1/2)n^2+(4/3)n-3/2

Which gives for n=1001: 669171001

[/Color]
 
I wrote a program and came up with the same answer.
Code:
class Diagonals{
	public static void main(String args[])
	{
		int x = 0, y = 0, sum = 0;
		for(int i = 1; i <= 1001*1001; i++)
		{
			if(Math.abs(x) == Math.abs(y))
				sum+=i;
			if(y >= Math.abs(x))
				x++;
			else if((y <= -x && x > 0) || (y < x && x <= 0))
				x--;
			else if(x > 0)
				y--;
			else if(x < 0)
				y++;
		}
		System.out.println(sum);
	}
}

How can I prove my program equivalent to your formula?
 
Galileo said:
Answer:


Argh, my stupid computer crashed while I finished typing out the solution here.
Luckily my closed form formula was still copied to mthe memory:
Sum of diagonals for the nxn spiral (n is odd): (2/3)n^3+(1/2)n^2+(4/3)n-3/2

Which gives for n=1001: 669171001

[/Color]
You were once the only author on the net to publish this formula. How do you come to this result? I published a similar formula much later. Sorry for not quoting you.

My contribution in APL Quote Quad (December 20027) fell in the category "APL as a tool of thought".

Regards
 
Tribute and addendum to Galileo's solution .
Perhaps someone can make use of the iteration math I am contributing to find a way to Galileo's formula.

Galileo's solution formula
(2/3)n^3+(1/2)n^2+(4/3)n-3/2The algorithm I made up used n^2 +((n-1)^2)+1)*3 for each +2 iteration starting at 1.
Starting at 2 it yields the even diagonal sums.
Your formula for even diagonals would leave out the last -3/2. Yours is a straightforward answer. Good one Galileo.

mathal
 
Last edited:
Andrex said:
You were once the only author on the net to publish this formula. How do you come to this result? I published a similar formula much later. Sorry for not quoting you.

My contribution in APL Quote Quad (December 20027) fell in the category "APL as a tool of thought".

Regards
Erratum: I mean "December 2007" (not "December 20027").
 
Back
Top