#Octave, 27 23 bytes
Octave, 27 23 bytes
@(x,y)sum(z=x:y)^2-z*z'
Creates an anonymous function named ans
which accepts two inputs: ans(lower, upper)
Explanation
Creates a row vector from x
to y
(inclusive) and stores it in z
. We then sum all the elements using sum
and square it (^2
). To compute the sum of the squares, we perform matrix multplication between the row-vector and it's transpose. This will effectively square each element and sum up the result. We then subtract the two.