Let X
1, X
2, X
3, ..., X
n be a permutation of the integers 1,2,3,...,n.
Consider the sum:
abs(X1-X3) + abs(X2-X4) + abs(X3-X5) + ... + abs(Xn-2-Xn).
What is the mean value of this sum taken over all possible permutations?
The average of any given term, abs(Xk-Xk+2) is what you would get by checking every combination of the first n numbers taken 2 at a time, and computing the absolute value of their difference.
The average of each term of the sum appears to be (n+1)/3
Since there are (n-2) terms, the average sum is (n+1)(n-2)/3 *********
n average term average sum (n+1)(n-2)/3
3 1.33333333 1.33333333 1.33333333
4 1.66666666 3.33333333 3.33333333
5 2.0 6.0 6.0
6 2.33333333 9.33333333 9.33333333
7 2.66666666 13.3333333 13.3333333
8 3.0 18.0 18.0
9 3.33333333 23.3333333 23.3333333
------------------------
from itertools import combinations
def avg_diff_combo2(n):
one2n = [i for i in range(1,n+1)]
# mymean = []
mysum = 0
for comb in combinations(one2n,2):
mysum += abs(comb[0] - comb[1])
return mysum / (n*(n-1)/2)
for n in range(3,10):
print(n, avg_diff_combo2(n), avg_diff_combo2(n)*(n-2), (n+1)*(n-2)/3)
|
Posted by Larry
on 2023-12-07 09:21:32 |