37
6
Find the difference between the square of the sums and sum of the squares.
This is the mathematical representation:
\$\left(\sum n\right)^2-\sum n^2\$
Your program/method should take two inputs, these are your lower and upper limits of the range, and are inclusive. Limits will be whole integers above 0.
Your program/method should return the answer.
You may use whichever base you would like to, but please state in your answer which base you have used.
Test case (Base 10)
5,9 970
91,123 12087152
1,10 2640
This is usual code-golf, so the shorter the answer the better.
11It took me a while to realize the input was the endpoints of a range. – Brad Gilbert b2gills – 2016-06-20T14:08:24.203
@BradGilbertb2gills edited for clarity – george – 2016-06-20T14:20:09.973
This is simpler than it looks ? – cat – 2016-06-22T20:17:42.853
@cat what do you mean by that? Yes the maths is simple Alevel stuff. But it's all down to how you golf it – george – 2016-06-22T20:18:59.837
@george The question and many of the answers make it look like a lot of work, but it's not
– cat – 2016-06-22T21:17:08.430@cat I never said it was a lot of work. As I mentioned above, it is simple Alevel mathematics. – george – 2016-06-22T21:18:40.597
I assume not, but may we take an array as input instead of the start and end points? – caird coinheringaahing – 2018-04-13T18:42:50.897
@cairdcoinheringaahing amazing that people are still going at it a year and half later. When I wrote it I said two inputs, so in theory you could pass two arrays as input, but it must be two. Not one away with both inputs. Although I’d be interested to see both solutions – george – 2018-04-13T20:23:16.003