The following sum is constituted for each permutation p
1, p
2, p
3,..., p
9, p
A, p
B, p
10 of the duodecimal (base 12) integers 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, 10:
|p1-p2|+|p3-p4|+|p5-p6|+|p7-p8|+|p9-pA|+|pB-p10|
Determine the average value of all such sums.
Summary: For n=12, I got 26, though my program took an hour to run.
Re-evaluating this at various numbers other than 12 leads to what appears to be the n-th triangular number divided by 3
n avg
2 1
4 10/3
6 7
8 12
10 55/3
12 26
--------
n=12
p = [i for i in range(1,n+1)]
from itertools import permutations
grandsum = 0
count = 0
for perm in permutations(p):
count += 1
s = 0
for i in range(1,n,2):
s += abs(perm[i-1] - perm[i])
grandsum += s
print(n,grandsum/count)
|
Posted by Larry
on 2022-12-19 07:03:49 |