News for hackers. Stuff that matters.
Re:Ask HN: How can I become a self-taught software engineer? by rodorgas on Sunday December 17, 2017 @04:29PM (#15947767)
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.

Re:Ask HN: How can I become a self-taught software engineer? by jfoutz on Sunday December 17, 2017 @05:30PM (#15948048)
Ah, 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.

Re:Ask HN: How can I become a self-taught software engineer? by zellyn on Sunday December 17, 2017 @10:04PM (#15949091)
See, 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.