Gauss is the Bad Boy

How to sum 1 … 10 ? Easy, (1+10)*10/2 = 55

But Why it can be like that ? let me explain

We Want to sum(s) 1 to 10, the equation will be

Sample 1 :

s = 1+2+3+4+5+6+7+8+9+10
s = 10+9+8+7+6+5+4+3+2+1
========================  +
2s = 11 + 11 + 11 + 11 + 11 + 11 + 11 + 11 + 11 + 11 + 11
2s = 10 * 11
s = (10 * 11)/2
s = (10 * (10+1))/2

Sample 2 :

We Want to sum(s) 2 to 14, the equation will be :

s = 2 + 3 + 4 + 5  + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14
s = 14 + 13 + 12 + 11 + 10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2
=============================================== +
2s = 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16
s = 12 * 16 / 2
s = (12 * (14 + 2)) / 2

Sum = n*(U1+Un)/2

And the most interesting story behind this formula is gauss write this on whiteboard when he is so bad and get punishment to count 1 to 100.

Source: http://id.wikipedia.org/wiki/Carl_Friedrich_Gauss

 
6
Kudos
 
6
Kudos

Now read this

Sirat, create your Pojo and We generate the query

I’m to lazy to create a pojo and a query to provide in contentprovider. So after thinking i’m have decide to cut this and create a tools to help that. So i’m created Sirat. Sirat (https://github.com/linggom/sirat/) is using annotation... Continue →