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.
So, the sum of 1..1024 is: 1024 * 1025 ÷ 2 = 524800.