broken image
Theres a popular story that Gauss, mathematician extraordinaire, had a lazy teacher. The so-called educator wanted to keep the kids busy so he could take a nap; he asked the class to add the numbers 1 to 100.
Keep It 1 8 21
6 1 2 Of 8
Keep It 1 8 20
Keep It 1.8.2 MacOS Full Keep It Available on Mac, and as a separate app for iPhone and iPad, Keep It is the destination for all those things you want to put somewhere, confident you will find them again later. Keep IT Simple provide design, implementation, transformation and ongoing support for Private or Public cloud environments running all Openstack, VMWare and Hyper-V. We provide certified AWS and Azure specialists to provide diligence in optimising your environments for maximum efficiency and the least possible cost. Version 1.8.16 - Fixed an issue saving web links as web archives on iOS 14 and iPadOS 14. Fixed a crash that could occur when switching between Keep It and another app in split view on iPadOS 14. Romans 2:8 But for those who are self-seeking and who reject the truth and follow wickedness, there will be wrath and anger. Galatians 4:8 Formerly, when you did not know God, you were slaves to those who by nature are not gods.
Gauss approached with his answer: 5050. So soon? The teacher suspected a cheat, but no. Manual addition was for suckers, and Gauss found a formula to sidestep the problem:
Lets share a few explanations of this result and really understand it intuitively. For these examples well add 1 to 10, and then see how it applies for 1 to 100 (or 1 to any number). Technique 1: Pair Numbers
Pairing numbers is a common approach to this problem. Instead of writing all the numbers in a single column, lets wrap the numbers around, like this:
An interesting pattern emerges: the sum of each column is 11 . As the top row increases, the bottom row decreases, so the sum stays the same.
Because 1 is paired with 10 (our n), we can say that each column has (n+1). And how many pairs do we have? Well, we have 2 equal rows, we must have n/2 pairs.
which is the formula above. Wait what about an odd number of items?
Ah, Im glad you brought it up. What if we are adding up the numbers 1 to 9? We dont have an even number of items to pair up. Many explanations will just give the explanation above and leave it at that. I wont.
Lets add the numbers 1 to 9, but instead of starting from 1, lets count from 0 instead:
By counting from 0, we get an extra item (10 in total) so we can have an even number of rows. However, our formula will look a bit different.
Notice that each column has a sum of n (not n+1, like before), since 0 and 9 are grouped. And instead of having exactly n items in 2 rows (for n/2 pairs total), we have n + 1 items in 2 rows (for (n + 1)/2 pairs total). If you plug these numbers in you get:
which is the same formula as before. It always bugged me that the same formula worked for both odd and even numbers wont you get a fraction? Yep, you get the same formula, but for different reasons. Technique 2: Use Two Rows
The above method works, but you handle odd and even numbers differently. Isnt there a better way? Yes.
Instead of looping the numbers around, lets write them in two rows:
Notice that we have 10 pairs, and each pair adds up to 10+1.
The total of all the numbers above is
But we only want the sum of one row, not both. So we divide the formula above by 2 and get:
Now this is cool (as cool as rows of numbers can be). It works for an odd or even number of items the same! Technique 3: Make a Rectangle Keep It 1 8 21
I recently stumbled upon another explanation, a fresh approach to the old pairing explanation. Different explanations work better for different people, and I tend to like this one better. Movist 2 1 100 .
Instead of writing out numbers, pretend we have beans. We want to add 1 bean to 2 beans to 3 beans all the way up to 5 beans.
Sure, we could go to 10 or 100 beans, but with 5 you get the idea. How do we count the number of beans in our pyramid?
Well, the sum is clearly 1 + 2 + 3 + 4 + 5. But lets look at it a different way. Lets say we mirror our pyramid (Ill use o for the mirrored beans), and then topple it over:
Cool, huh? In case youre wondering whether it really lines up, it does. Take a look at the bottom row of the regular pyramid, with 5x (and 1 o). The next row of the pyramid has 1 less x (4 total) and 1 more o (2 total) to fill the gap. Just like the pairing, one side is increasing, and the other is decreasing.
Now for the explanation: How many beans do we have total? Well, thats just the area of the rectangle.
We have n rows (we didnt change the number of rows in the pyramid), and our collection is (n + 1) units wide, since 1 o is paired up with all the xs.
Notice that this time, we dont care about n being odd or even the total area formula works out just fine. If n is odd, well have an even number of items (n+1) in each row.
But of course, we dont want the total area (the number of xs and os), we just want the number of xs. Since we doubled the xs to get the os, the xs by themselves are just half of the total area:
And were back to our original formula. Again, the number of xs in the pyramid = 1 + 2 + 3 + 4 + 5, or the sum from 1 to n. Technique 4: Average it out
We all know that
average = sum / number of items
which we can rewrite to
sum = average * number of items
So lets figure out the sum. If we have 100 numbers (1100), then we clearly have 100 items. That was easy. Memory clean 2: free up memory 1 8 .
To get the average, notice that the numbers are all equally distributed. For every big number, theres a small number on the other end. Lets look at a small set:
The average is 2. 2 is already in the middle, and 1 and 3 cancel out so their average is 2.
For an even number of items
the average is between 2 and 3 its 2.5. Even though we have a fractional average, this is ok since we have an even number of items, when we multiply the average by the count that ugly fraction will disappear.
Notice in both cases, 1 is on one side of the average and N is equally far away on the other. So, we can say the average of the entire set is actually just the average of 1 and n: (1 + n)/2.
Putting this into our formula
And voila! We have a fourth way of thinking about our formula. So why is this useful?
Three reasons: 6 1 2 Of 8
1) Adding up numbers quickly can be useful for estimation. Notice that the formula expands to this:
Lets say you want to add the numbers from 1 to 1000: suppose you get 1 additional visitor to your site each day how many total visitors will you have after 1000 days? Since thousand squared = 1 million, we get million / 2 + 1000/2 = 500,500 .
2) This concept of adding numbers 1 to N shows up in other places, like figuring out the probability for the birthday paradox. Having a firm grasp of this formula will help your understanding in many areas. Keep It 1 8 20
3) Most importantly, this example shows there are many ways to understand a formula. Maybe you like the pairing method, maybe you prefer the rectangle technique, or maybe theres another explanation that works for you. Dont give up when you dont understand try to find another explanation that works. Happy math.
By the way, there are more details about the history of this story and the technique Gauss may have used. Variations
Instead of 1 to n, how about 5 to n?
Start with the regular formula (1 + 2 + 3 + + n = n * (n + 1) / 2) and subtract off the part you dont want (1 + 2 + 3 + 4 = 4 * (4 + 1) / 2 = 10).
And for any starting number a:
We want to get rid of every number from 1 up to a 1.
How about even numbers, like 2 + 4 + 6 + 8 + + n?
Just double the regular formula. To add evens from 2 to 50, find 1 + 2 + 3 + 4 + 25 and double it:
So, to get the evens from 2 to 50 youd do 25 * (25 + 1) = 650
Principle 3 7. How about odd numbers, like 1 + 3 + 5 + 7 + + n?
Thats the same as the even formula, except each number is 1 less than its counterpart (we have 1 instead of 2, 3 instead of 4, and so on). We get the next biggest even number (n + 1) and take off the extra (n + 1)/2 -1 items:
To add 1 + 3 + 5 + 13, get the next biggest even (n + 1 = 14) and do
Combinations: evens and offset
Lets say you want the evens from 50 + 52 + 54 + 56 + 100. Find all the evens
and subtract off the ones you dont want
So, the sum from 50 + 52 + 100 = (50 * 51) (24 * 25) = 1950
Phew! Hope this helps.
Ruby nerds: you can check this using
Javascript geeks, do this: Join Over 450k Monthly Readers
Enjoy the article? There's plenty more to help you build a lasting, intuitive understanding of math. Join the newsletter for bonus content and the latest updates.
Other Posts In This Series
broken image