Zsh --force_float
, 141 136 109 10196 bytes
Try it online!Try it online!
109bytes109bytes
136bytes
141bytes
m=$1 n=$1
forn=$1;for x ((t+=x,m=x>m?x:m,n=x<n?x:n,s=2*(#>2?(t-m-n)/(#-2):t/#)))
<<<$[(s^0+(s-s^0>.5?1:0))/2]
Solution follows latest spec, except for the unclear second test case. Saved a few bytes using implicit ($@)
. Saved more by moving most calculations into the (( ))
statement.
We implicitly iterate over the arguments with for x
, and build a running total t
, and also find maxima, minima m, n
. If the number of arguments #
is greater than 2, we discard m
and n
from the average. s
is 2x the resulting average. If the mantissa of s
is greater than 0.5, round s
up, otherwise truncate with s^0
. Finally, divide by 2 and output.