Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Sum of diagonals

  1. Apr 21, 2005 #1
    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?
     
  2. jcsd
  3. Apr 23, 2005 #2
    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.
     
  4. Apr 23, 2005 #3

    Galileo

    User Avatar
    Science Advisor
    Homework Helper

    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

     
  5. Apr 23, 2005 #4
    I wrote a program and came up with the same answer.
    Code (Text):

    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?
     
  6. Aug 9, 2011 #5
    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
     
  7. Aug 11, 2011 #6
    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/2


    The 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: Aug 11, 2011
  8. Aug 13, 2011 #7
    Erratum: I mean "December 2007" (not "December 20027").
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Sum of diagonals
  1. Sum of series? (Replies: 10)

  2. Diagonal Frog (Replies: 4)

Loading...