re: That programming book you never finished VIEW POST


Try reducing computation by finding a closed form instead of writing a loop. Here, the closed form is f(n) = n*(n+1) (e.g. f(100) = 100*101 = 10100):

f(n) = S[1..n] 2*i     definition
     = 2 * S[1..n] i   pull out the coefficient
     = 2 * n*(n+1)/2   by triangular number formula
     = n*(n+1)         cancel the twos
Code of Conduct Report abuse