3 ms·
Sure, here's one: given a list of n items, compute the sum of pairwise distances between every pair of items. The first item has distance 1 from the second, 2
by reinhardt 15y ago
Sure, here's one: given a list of n items, compute the sum of pairwise distances between every pair of items.
The first item has distance 1 from the second, 2 from the third, ..., n-1 from the last. Similarly, the second item has distance 1 from the third, 2 from the fourth, ..., n-1 from the last. And so on until the (n-1)-th item.
Expressed as a finite sum, this amounts to:
sum (sum j, j=1 to n-i), i=1 to n-1
Paste this to Wolphram Alpha and you get the answer in a closed form:
http://www.wolframalpha.com/input/?i=sum+%28sum+j%2C+j%3D1+to+n-i%29%2C+i%3D1+to+n-1 http://www.wolframalpha.com/input/?i=sum+%28sum+j%2C+j%3D1+t...