Olympic game scoring
Jelly, 12 bytes
ṢṖḊȯµÆmḤær0H
Try it online!
µ Take
Ṣ the input sorted,
Ṗ without its last
Ḋ or first element,
ȯ or the unchanged input if that's empty,
Æm then calculate the mean,
Ḥ double it,
ær round it to the nearest multiple of
0 10^-0 (= 1),
H and halve it.
A version which rounds halves down, in accordance with the spec at the expense of the second test case:
Jelly, 12 bytes
ṢṖḊȯµÆmḤ_.ĊH
Try it online!
The rounding method here is closer to Jonathan Allan's:
Ḥ Double,
_ subtract
. one half,
Ċ round up,
H and halve.
Retina, 86 bytes
\.5
__
\d+
*4*__
O`_+
_+ (.+) _+
$1
O`.
^ *
$.&*__:
(_+):(\1{4})*(\1\1)?_*
$#2$#3*$(.5
Try it online! Link includes test cases. Explanation:
\.5
__
\d+
*4*__
Since Retina can't readily handle fractional or zero numbers, each number is represented in unary as 1 more than 4 times the value. The .5
therefore expands to 2 _
s, while the *4*_
applies to the whole number part, and a final _
is suffixed.
O`_+
Sort the numbers into order.
_+ (.+) _+
$1
If there are at least three numbers, discard the first (smallest) and last (largest).
O`.
Sort the spaces to the start, thus also summing the numbers.
^ *
$.&*__:
Count the number of spaces and add _
and a separator. This then represents the number we have to divide by.
(_+):(\1{4})*(\1\1)?_*
$#2$#3*$(.5
Divide the sum by the number of numbers, allowing for the fact that we're working in multiples of 4 times the original number, so that the integer and decimal portions can be directly extracted. This is a truncating division, but fortunately because we added an extra _
to each number, the result effectively includes an extra 0.25, thus giving us the rounding we want.
EDIT: This answer has since become invalid. It was valid for about half a minute after it was posted.
Jelly, 10 bytes
ṢḊṖȯƊÆmḤḞH
Try it online!