5 ms·
I searched for it and it would be more something like this: . .. ... .... That's 1 + 2 + 3 + 4. To sum, double the triangle, you'll get a rectangle:
by rodorgas 9y ago
I searched for it and it would be more something like this:
.
..
...
....
That's 1 + 2 + 3 + 4. To sum, double the triangle, you'll get a rectangle:
.oooo
..ooo
...oo
....o
1 + 2 + 3 + 4 = area ÷ 2 = (4 * 5) ÷ 2 = 10.
So, the sum of 1..1024 is: 1024 * 1025 ÷ 2 = 524800.
- jfoutz 9y agoAh, that's a much more direct interpretation. I'd always considered the /2 to mean find the middle element. take the biggest and the smallest, add them, and multiply by the middle. Which is a little closer to my drawing. My interpretation is bad, because i'd always have to mentally special case odd length sequences. Your way, the doubling is obvious, so you see why you can always /2 at the end. Hmm. Haven't thought about this stuff in years. This was a pretty pleasing thing to revisit.
- zellyn 9y agoSee, my obnoxious questions are awesome :-p Actually, I came here to post the correction rodorgas beat me to posting. But your diagram works too: 1/2 base * height… nice.