태그 보관물: set-partitions

set-partitions

사 분위수 평균 참조하십시오 . 평가 예 1 주어진 {1, 3,

태스크

정렬 된 부동 소수점 데이터 세트가 주어진 경우 ( 사소한 방법으로 올바른 값의 1 ‰ 이내) 사 분위수 평균을 반환 합니다.

하나의 가능한 알고리즘

  1. 데이터 포인트의 최저 및 최고 분기를 폐기하십시오.
  2. 나머지 데이터 포인트의 평균 (수를 수로 나눈 값)을 계산합니다.

참고 : 데이터 세트 크기를 4 개로 균등하게 분할 할 수없는 경우 하위 세트가 공유 하는 데이터 포인트의 무게측정해야 합니다. 아래의 평가 예 2를 참조하십시오 .

평가 예 1

주어진 {1, 3, 4, 5, 6, 6, 7, 7, 8, 8, 9, 38}

  1. 데이터 수는 12이므로 가장 낮고 가장 높은 3 개의 데이터 포인트를 제거합니다.
    { 1, 3, 4, 5, 6, 6, 7, 7, 8, 8, 9, 38 }
  2. 나머지 6 개 데이터 포인트의 평균 :
    (5 + 6 + 6 + 7 + 7 + 8) / 6 = 6.5

평가 예 2

주어진 {1, 3, 5, 7, 9, 11, 13, 15, 17}

  1. 개수는 9이므로 각 분기에는 2 1/4 데이터 포인트가 있습니다 :
    { 1, 2, (0.25 × 5), (0.75 × 5), 7, 9, 11, (0.75 × 13), (0.25 × 13), 15, 17 }
  2. 나머지 4.5 데이터 포인트의 평균 :
    (0.75 × 5 + 7 + 9 + 11 + 0.75 × 13) / 4.5 = 9


답변

Scilab, 8 바이트

trimmean

설명서를 참조하십시오 . 기본적으로 discard=50IQM이 계산됩니다.

편집 : 알다시피, 이것은 사소한 내장 답변이므로 CW로 표시하고 있습니다 .


답변

Pyth , 11 10 바이트

.O> <1QS * 4Ql
.OsPtc4S * 4

테스트 스위트.

작동 원리

데이터 수를 4로 나눌 수 있도록 입력 목록을 4 배로 만듭니다.

*4각 개별 요소 대신 전체 목록에 적용 되므로 여전히 정렬이 필요합니다 .

그런 다음 목록을 4 개의 동일한 부분으로 나누고 첫 번째 부분과 마지막 부분을 제거합니다.

나머지 목록은 평평 해지고 평균이 취해집니다.


답변

MATL , 12 11 바이트

4Y"G"6L)]Ym

입력은 형식이있는 수평 벡터입니다.

[1, 3, 4, 5, 6, 6, 7, 7, 8, 8, 9, 38]

또는

[1 3 4 5 6 6 7 7 8 8 9 38]

온라인으로 사용해보십시오!

설명

4Y"    % Input horizontal vector implicitly. Repeat each element 4 times (run-length
       % decoding). The resulting array is still sorted.
G"     % Push input, for each: repeat as many times as the input size
  6L)  %   Remove first and last elements, by applying the index "2:end-1"
]      % End for each
Ym     % Compute mean. Display implicitly


답변

눈사람 , 66 바이트

}vg","aS:10sB;aM4aRAsOal`,4nD,`aG0AaGal`NdE`AaL1AfL:nA;alaF,nDtSsP

온라인으로 사용해보십시오!

@LeakyNun 의 답변 과 동일한 알고리즘을 사용합니다 .

}         enable variables b, e, and g
vg        read a line of input into b
","aS     split on commas (in-place)
:10sB;aM  convert each element in resulting array to number ("frombase(10)-map")
4aR       repeat the array 4 times
AsO       sort the array
al        take the length and put it in e without consuming b (the array)
`,        swap b and e, then move e to g; now b=length g=array
4nD       divide b by 4 (4 was stored in e, which is why the array was moved)
,`        move the array and length/4 back to their original positions
aG        split the array into groups of length (length/4)
0AaG      take all elements with index >0 (i.e. remove the first element)
al        store the length of the new array in e again
`NdE`     bring it up to b, decrement, and put it back
AaL       take all elements with index <length-1 (i.e. remove last)
1AfL      flatten the array 1 level deep
:nA;      push a block that adds two numbers (to e)
al        store the length of this new array in g
aF        fold b over e (sum the numbers)
,         move g (the length) into e
nD        divide the sum by the length, resulting in the average
tSsP      to-string and print


답변

파이썬 3, 50 바이트

lambda n:sum(sorted(n*4)[len(n):-len(n)])/len(n)/2

무시 했어!

작동 원리

그것은 Pyth에서대답을 번역 한 것입니다 .


답변

젤리 , 14 13 12 바이트

x4ṫL '$ ḣLN $ S ÷ LH 
x4ṫLḊḣLN $ S ÷ LH
x4–s4ḊṖFS ÷ LH

온라인으로 사용해보십시오!

테스트 스위트.

작동 원리

그것은 Pyth에서대답을 번역 한 것입니다 .


답변

파이크, 16 13 바이트

4*S4ftOsDsRl/

여기 사용해보십시오!