All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Alternating Differences (Posted on 2023-12-07) Difficulty: 3 of 5
Let X1, X2, X3, ..., Xn 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?

See The Solution Submitted by K Sengupta    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution No Subject | Comment 1 of 3
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
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (1)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (6)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information