# Find a number/s around average that meet a specific property

Lets say I have a specific list of numbers (33 in this case):

deltas = [24.81, 25.94, 26.18, 26.36, 26.49, 26.63, 26.63, 26.53, 26.53, 26.57, 26.55, 25.67, 25.9, 26.12, 26.35, 26.23, 26.56, 26.37, 26.5, 26.53, 26.73, 26.88, 27.03, 27.12, 27.77, 28.06, 28.6, 29.03, 29.12, 29.44, 29.31, 29.52, 27.45]


where:

size = len(deltas) # 33
delta_sum = sum(deltas) # 891.51
average = np.average(deltas) # 27.015454545454549
median = np.median(deltas) # 26.559999999999999


now these deltas produce another list of cumulative values where each element is the current sum.

s = 0
cumulatives = []
for delta in deltas:
s += delta
cumulatives.append(s)

# cumulatives = [24.81, 50.75, 76.93, 103.29, 129.78, 156.41, 183.04, 209.57, 236.1, 262.67, 289.22, 314.89000000000004, 340.79, 366.91, 393.26000000000005, 419.49000000000007, 446.05000000000007, 472.4200000000001, 498.9200000000001, 525.45, 552.1800000000001, 579.0600000000001, 606.09, 633.21, 660.98, 689.04, 717.64, 746.67, 775.79, 805.23, 834.54, 864.06, 891.51]


I want to find out if/when there is a number x (or a range of numbers) where for every s from the list of cumulatives: s divided by x and rounded to the closest integer will be equal to the position of s in the list.

e.g. for the 3rd element from cumulatives: 76.93

round(76.93/x) should produce 3.


If we take the average or median this will be true for the most of the values in cumulatives, but not for all of them!

For example, if we use the average = 27.015454545454549, its true for element 17: round(446.05/average) == 17, but not for element 18: 472.42/average ~= 17.487 ~= 17

If we use the median = 26.559999999999999, its not true only for the last 2 elements (32 and 33).

32: 864.06/median ~= 32.53 ~= 33
33: 891.51/median ~= 33.567 ~= 34


I know there is such x which satisfies the criteria for all elements in cumulatives, such a number is any number in the range: [26.613:26.933] (found the range by brute-force).

I don't know if its by accident, but the average of average and median is inside this range: (average+median)/2 ~= 26.787.

all((n+1 == int(round(c/26.787)) for n, c in enumerate(cumulatives))) # True


Don't know if this will aways be the case? Is there a way to prove it?

It will not always be the case. Consider the set $\{1,2,6\}$ (your "deltas"). Then your set of "cumulatives" is $\{1,3,9\}$. The mean of the deltas is $\mu=3$, the median is $m=2$. Let $z=\frac{\mu+m}{2}=5/2$. We have $9/z=18/5=3.6$, which is $4$ rounded to the nearest integer, not $3$. I think it works for your example because the gap between each delta is less than one or a little larger than one.
• The problem with {1,3,9} is that there is no such $\hat x$ where $int(round(\frac{x_i}{\hat x})) = i$ for every $x_i$ in the set. I want to find an algorithm which can say if such $\hat x$ exists for a given set or not (and then find that $\hat x$ once I know it exists). My initial assumption was that using $\mu$ or $m$ will be sufficient, but the example from the question shows, that they are not and yet $\hat x$ exists for the set. PS. Yes the deltas are not in order, but they will aways be positive, which makes the list of cumulatives ordered. Commented Mar 30, 2018 at 6:19