-2

I want to find a specific algorithm to choose either 2 or 3 out of 3 given values. Like if I have a set of values 10,11,12 all three are close enough so I will calculate the mean of the value and return the mean. For another example if the values are 6,10,12. then I will choose 10 and 12 and calculate the mean and return the mean. Though these value can not necessarily be of of this range , they can go in thousands as well . But there will only be three number of values . I hope I am clear enough. I am not sure how to proceed over this and I need some help . Thank you

2 Answers2

0

Simply calculated all 4 possible selects (3 possibilities for 2 values, 1 for all three), calculate the means, check which one 'like' the most and return it.

So the only problem is to define 'close enough' to decide which of the 4 means is the one you want to return.

MrSmith42
  • 9,961
  • 6
  • 38
  • 49
0

python version:

def algo(a:int, b:int, c:int, threshold:int):
        n=[0,0,0]
        s=0
        if(abs(a-b)<=threshold):
            s+=(1-n[0])*a+(1-n[1])*b
            n[0]=1
            n[1]=1
        if(abs(a-c)<=threshold):
            s+=(1-n[0])*a+(1-n[2])*c
            n[0]=1
            n[2]=1
        if(abs(c-b)<=threshold):
            s+=(1-n[1])*b+(1-n[2])*c
            n[1]=1
            n[2]=1
        return s/sum(n)
Grzegorz Skibinski
  • 12,624
  • 2
  • 11
  • 34