Untitled
public text v1 · immutableS = 1 + 2 + 3 + ... + n
we want to find S
rewrite S backwards:
S = n + (n-1) + (n-2) + ... + 3 + 2 + 1
then add both versions of S to each other...
so S + S =
1 + 2 + 3 + ... + (n-2) + (n-1) + n +
n + (n-1) + (n-2) + ... + 3 + 2 + 1
and notice, if we add each two values above each other together we get:
(n+1) + (n+1) + (n+1) + ... + (n+1) (n times)
so we have
S + S = 2S = n*(n+1)
hence
S = n(n+1)/2