Note this kind of outliers goes to statistics.
My idea: We need to compare all the numbers and the one that is more different from everything is superfluous.
That code has been written by my friend, It doesn't work at all but still. You may take some idea from it here it is.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function solution(...) arg.n = nil local tab = {} local count = 0 local value = 0 for i, k in pairs(arg) do for l, n in pairs(arg)do if (i ~= l) then count = count + 1 value = value + math.abs(k-n) if (math.abs(k-n) > value/count) then if (tab[k] ~= nil) then tab[k] = tab[k] + 1 else tab[k] = 1 end if (tab[n] ~= nil) then tab[n] = tab[n] + 1 else tab[n] = 1 end end end end end local max = 0 local excess for i, k in pairs(tab) do if (max < k) then max = k excess = i end end return excess end print(solution(1,2,14,4,5,3)) --14 print(solution(100,99,88,78,1)) --1
Would be appreciated
edited 2×, last 13.05.20 04:10:45 pm