Anyone See the Pattern?

[update] Understanding why for n=1;n+2 ((n^2)-1)%8==0 isn't the point of this exercise...look at the pattern in the results of each iteration. That's what has me baffled. Haacked has a great proof explaining what's going on on the left side of the operand, but I'm more interested in what's up with the right side. [/update]

This just popped into my head the other day for no other reason than to bug me: Square all odd numbers starting with 1…subtract 1 from the result…then divide by 8. Now look for the pattern in the results.

static void Process(int count)

{

for (int i = 1; i < count; i += 2)

{

` int iSquared = (i * i);`

` if (((iSquared) - 1) % 8 == 0)`

{

` int result = ((iSquared - 1) / 8);`

Console.WriteLine(i + "^2 = " + iSquared + " - 1 = " + ((iSquared) - 1) + " / 8 = " + result);

}

` else`

{

` Console.WriteLine("false");`

}

}

Console.ReadLine();

}

Squint for a second or 2 and you’ll see it. Anyone out there with a degree in mathematics care to explain **why** that happens?

Posted Thu, Oct 20 2005 7:21 PM by Jayson Knight

Filed under: .Net

on Fri, Oct 21 2005 4:45 AM

I don't know why your formula get the numbers, but that's the triangular number series... http://ptri1.tripod.com/#tri

on Fri, Oct 21 2005 4:48 AM

More info here: http://mathworld.wolfram.com/TriangularNumber.html

on Fri, Oct 21 2005 9:35 AM

Well! 1- About your pattern: You've been hacked proved it but I'm looking for a way to prove his proof is true in all cases or give another proof. 2- I haven't use EiffelEnvision yet but try to check it asap. Thank you for references. 3- Maryam Ghaemmaghami (Scoble's wife) is Iranian and live in US. I don't like to check the stats of my website. Sometimes I use an application (It uses IIS logs) to check my referrers and total hits. It has good details. For my blog I think that the number of hits are depend on my posts so try to write better. Although I don't write to get better traffics. But thank you for StatsCounter it's a great website ;) On the other hand if you read my last posts I analyze the traffic with some statistical methods (Time Series) and they are absolutely better than this kind of stats. 4- This comment: http://nayyeri.net/archive/2005/10/08/207.aspx#238 beat me to give this link if you want to use GTalk with Trillian (Pro version): http://www.google.com/support/talk/bin/answer.py?answer=24077&topic=1415

on Fri, Oct 21 2005 9:49 AM

Well my proof is true in all cases where x is an odd integer. The same is not true for n being even. I wrote more on the Triangular series in the comments of my post. The pattern you see is a consequence of the triangular series as the commenter said. Check out this... http://ptri1.tripod.com/ Scroll down to triangular numbers. See how they are a part of Pascal's triangle? Interesting eh?

on Fri, Oct 21 2005 11:12 AM

I think I answered your question better in my latest post (http://haacked.com/archive/2005/10/21/10910.aspx). I try and explain WHY your formula gets the triangular series. It's an algebraic identity.

on Fri, Oct 21 2005 1:15 PM

Yesterday&nbsp;Jayson Knight had pointed to a pattern in sequence of odd numbers and had written a code...

on Sat, Oct 22 2005 2:27 AM

And of course there's a Wiki on the triangular number series: http://en.wikipedia.org/wiki/Triangular_number

on Fri, Dec 30 2005 1:39 AM

One thing that really bugs me about blogs is that it&rsquo;s still really damn hard to find specific...

on Sun, Jul 16 2006 2:13 AM

YesterdayJayson Knight had pointed to a pattern in sequence of odd numbers and had written a code to