Olympic game scoringFloating point addition, without floats!Un-round fractionsShrinking numbersConvert any...
Are there any “Third Order” acronyms used in space exploration?
How do we know that black holes are spinning?
How does a simple logistic regression model achieve a 92% classification accuracy on MNIST?
What officially disallows US presidents from driving?
What was the ultimate objective of The Party in 1984?
What explanation do proponents of a Scotland-NI bridge give for it breaking Brexit impasse?
Is there a tool to measure the "maturity" of a code in Git?
Interaction between Teferi Time Raveler and Enduring Ideal
Why is the UK still pressing on with Brexit?
geschafft or geschaffen? which one is past participle of schaffen?
How to give my students a straightedge instead of a ruler
How to publish superseding results without creating enemies
Why don't Wizards use wrist straps to protect against disarming charms?
Some Prime Peerage
What is a "major country" as named in Bernie Sanders' Healthcare debate answers?
2000s space film where an alien species has almost wiped out the human race in a war
Python web-scraper to download table of transistor counts from Wikipedia
What 68-pin connector is this on my 2.5" solid state drive?
What next step can I take in solving this sudoku?
Bit one of the Intel 8080's Flags register
How to be sure services and researches offered by the University are not becoming cases of unfair competition?
Is using gradient descent for MIP a good idea?
How do certain apps show new notifications when internet access is restricted to them?
ColorFunction based on array index in ListLinePlot
Olympic game scoring
Floating point addition, without floats!Un-round fractionsShrinking numbersConvert any number (up to 1e3000) to textJapanese Mahjong Score CalculatorBuilding DemolitionLet's learn some soil pH chemistry!Compound Interest… with Wizard MoneyDetermine Beckett Grading Service (BGS) Final Grade
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
$begingroup$
The challenge is to write a golf-code program that, given n positive real numbers from 0 to 10 (format x.y, y only can be 0 or 5: 0, 0.5, 1, 1.5, 2, 2.5 … 9.5 and 10), discard the lowest and highest values (only one, even though they are repeated) and shows the average of the remaining, in x.y format (y can be 0 or 5, rounded to closest), similar to some Olympic Games scoring.
Examples:
Input -> Output
6 -> 6
6.5, 9 -> 8
9, 7, 8 -> 8
6, 5, 7, 8, 9 -> 7
5, 6.5, 9, 8, 7 -> 7
6.5, 6.5, 9.5, 8, 7 -> 7
5, 6.5, 7.5, 8.5, 9.5 -> 7.5
Notes: If the input is only two numbers, do not discard any, just average them. If the input is one number, the output is the same.
Clarifying the rounding rule (sorry, little confuse):
x.01 to x.25 round to x.0
x.26 to x.75 round to x.5
x.76 to x.99 round to x+1.0
code-golf math average
New contributor
JuanCa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
|
show 12 more comments
$begingroup$
The challenge is to write a golf-code program that, given n positive real numbers from 0 to 10 (format x.y, y only can be 0 or 5: 0, 0.5, 1, 1.5, 2, 2.5 … 9.5 and 10), discard the lowest and highest values (only one, even though they are repeated) and shows the average of the remaining, in x.y format (y can be 0 or 5, rounded to closest), similar to some Olympic Games scoring.
Examples:
Input -> Output
6 -> 6
6.5, 9 -> 8
9, 7, 8 -> 8
6, 5, 7, 8, 9 -> 7
5, 6.5, 9, 8, 7 -> 7
6.5, 6.5, 9.5, 8, 7 -> 7
5, 6.5, 7.5, 8.5, 9.5 -> 7.5
Notes: If the input is only two numbers, do not discard any, just average them. If the input is one number, the output is the same.
Clarifying the rounding rule (sorry, little confuse):
x.01 to x.25 round to x.0
x.26 to x.75 round to x.5
x.76 to x.99 round to x+1.0
code-golf math average
New contributor
JuanCa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
2
$begingroup$
How is the second example (6.5, 9 => 8) valid? If you throw out the high and the low, there are no values left to average?
$endgroup$
– Jeff Zeitlin
8 hours ago
4
$begingroup$
I'd suggest we do not handle invalid input, the Olympics will have a fixed number of judges greater than two for such an event. (Diving removes the four extremities from seven for example)
$endgroup$
– Jonathan Allan
8 hours ago
2
$begingroup$
Ah, we have to special case when given two judge's scores, that's a little odd.
$endgroup$
– Jonathan Allan
7 hours ago
2
$begingroup$
Are we to use round-half-up rounding - for example[5, 6, 6, 10, 11, 13]leads to an average of8.25, should we output8.0or8.5?
$endgroup$
– Jonathan Allan
7 hours ago
2
$begingroup$
Your example6.5, 9disagrees with your spec which indicates that x.75 rounds to x.5.
$endgroup$
– Nick Kennedy
3 hours ago
|
show 12 more comments
$begingroup$
The challenge is to write a golf-code program that, given n positive real numbers from 0 to 10 (format x.y, y only can be 0 or 5: 0, 0.5, 1, 1.5, 2, 2.5 … 9.5 and 10), discard the lowest and highest values (only one, even though they are repeated) and shows the average of the remaining, in x.y format (y can be 0 or 5, rounded to closest), similar to some Olympic Games scoring.
Examples:
Input -> Output
6 -> 6
6.5, 9 -> 8
9, 7, 8 -> 8
6, 5, 7, 8, 9 -> 7
5, 6.5, 9, 8, 7 -> 7
6.5, 6.5, 9.5, 8, 7 -> 7
5, 6.5, 7.5, 8.5, 9.5 -> 7.5
Notes: If the input is only two numbers, do not discard any, just average them. If the input is one number, the output is the same.
Clarifying the rounding rule (sorry, little confuse):
x.01 to x.25 round to x.0
x.26 to x.75 round to x.5
x.76 to x.99 round to x+1.0
code-golf math average
New contributor
JuanCa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
The challenge is to write a golf-code program that, given n positive real numbers from 0 to 10 (format x.y, y only can be 0 or 5: 0, 0.5, 1, 1.5, 2, 2.5 … 9.5 and 10), discard the lowest and highest values (only one, even though they are repeated) and shows the average of the remaining, in x.y format (y can be 0 or 5, rounded to closest), similar to some Olympic Games scoring.
Examples:
Input -> Output
6 -> 6
6.5, 9 -> 8
9, 7, 8 -> 8
6, 5, 7, 8, 9 -> 7
5, 6.5, 9, 8, 7 -> 7
6.5, 6.5, 9.5, 8, 7 -> 7
5, 6.5, 7.5, 8.5, 9.5 -> 7.5
Notes: If the input is only two numbers, do not discard any, just average them. If the input is one number, the output is the same.
Clarifying the rounding rule (sorry, little confuse):
x.01 to x.25 round to x.0
x.26 to x.75 round to x.5
x.76 to x.99 round to x+1.0
code-golf math average
code-golf math average
New contributor
JuanCa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
JuanCa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 7 hours ago
JuanCa
New contributor
JuanCa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 8 hours ago
JuanCaJuanCa
335 bronze badges
335 bronze badges
New contributor
JuanCa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
JuanCa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
$begingroup$
How is the second example (6.5, 9 => 8) valid? If you throw out the high and the low, there are no values left to average?
$endgroup$
– Jeff Zeitlin
8 hours ago
4
$begingroup$
I'd suggest we do not handle invalid input, the Olympics will have a fixed number of judges greater than two for such an event. (Diving removes the four extremities from seven for example)
$endgroup$
– Jonathan Allan
8 hours ago
2
$begingroup$
Ah, we have to special case when given two judge's scores, that's a little odd.
$endgroup$
– Jonathan Allan
7 hours ago
2
$begingroup$
Are we to use round-half-up rounding - for example[5, 6, 6, 10, 11, 13]leads to an average of8.25, should we output8.0or8.5?
$endgroup$
– Jonathan Allan
7 hours ago
2
$begingroup$
Your example6.5, 9disagrees with your spec which indicates that x.75 rounds to x.5.
$endgroup$
– Nick Kennedy
3 hours ago
|
show 12 more comments
2
$begingroup$
How is the second example (6.5, 9 => 8) valid? If you throw out the high and the low, there are no values left to average?
$endgroup$
– Jeff Zeitlin
8 hours ago
4
$begingroup$
I'd suggest we do not handle invalid input, the Olympics will have a fixed number of judges greater than two for such an event. (Diving removes the four extremities from seven for example)
$endgroup$
– Jonathan Allan
8 hours ago
2
$begingroup$
Ah, we have to special case when given two judge's scores, that's a little odd.
$endgroup$
– Jonathan Allan
7 hours ago
2
$begingroup$
Are we to use round-half-up rounding - for example[5, 6, 6, 10, 11, 13]leads to an average of8.25, should we output8.0or8.5?
$endgroup$
– Jonathan Allan
7 hours ago
2
$begingroup$
Your example6.5, 9disagrees with your spec which indicates that x.75 rounds to x.5.
$endgroup$
– Nick Kennedy
3 hours ago
2
2
$begingroup$
How is the second example (6.5, 9 => 8) valid? If you throw out the high and the low, there are no values left to average?
$endgroup$
– Jeff Zeitlin
8 hours ago
$begingroup$
How is the second example (6.5, 9 => 8) valid? If you throw out the high and the low, there are no values left to average?
$endgroup$
– Jeff Zeitlin
8 hours ago
4
4
$begingroup$
I'd suggest we do not handle invalid input, the Olympics will have a fixed number of judges greater than two for such an event. (Diving removes the four extremities from seven for example)
$endgroup$
– Jonathan Allan
8 hours ago
$begingroup$
I'd suggest we do not handle invalid input, the Olympics will have a fixed number of judges greater than two for such an event. (Diving removes the four extremities from seven for example)
$endgroup$
– Jonathan Allan
8 hours ago
2
2
$begingroup$
Ah, we have to special case when given two judge's scores, that's a little odd.
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
Ah, we have to special case when given two judge's scores, that's a little odd.
$endgroup$
– Jonathan Allan
7 hours ago
2
2
$begingroup$
Are we to use round-half-up rounding - for example
[5, 6, 6, 10, 11, 13] leads to an average of 8.25, should we output 8.0 or 8.5?$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
Are we to use round-half-up rounding - for example
[5, 6, 6, 10, 11, 13] leads to an average of 8.25, should we output 8.0 or 8.5?$endgroup$
– Jonathan Allan
7 hours ago
2
2
$begingroup$
Your example
6.5, 9 disagrees with your spec which indicates that x.75 rounds to x.5.$endgroup$
– Nick Kennedy
3 hours ago
$begingroup$
Your example
6.5, 9 disagrees with your spec which indicates that x.75 rounds to x.5.$endgroup$
– Nick Kennedy
3 hours ago
|
show 12 more comments
9 Answers
9
active
oldest
votes
$begingroup$
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.
$endgroup$
$begingroup$
Just so happens to accidentally comply with the update to the spec
$endgroup$
– Unrelated String
7 hours ago
$begingroup$
@NickKennedy If I don't round, that case produces 6.8, which should round up to 7 according to the spec since 6.75 < 6.8 ≤ 7.
$endgroup$
– Unrelated String
5 hours ago
1
$begingroup$
sorry one two many 7s. I meant[1,10,6,7,7,7]
$endgroup$
– Nick Kennedy
3 hours ago
1
$begingroup$
Oh, yeah, it does do that one wrong.
$endgroup$
– Unrelated String
3 hours ago
add a comment
|
$begingroup$
Jelly, 12 bytes
ṢṖḊȯ⁸ÆmḤ+.ḞH
A monadic Link accepting a list of numbers which yields a number.
Try it online!
How?
ṢṖḊȯ⁸ÆmḤ+.ḞH - Link, list of numbers, X
Ṣ - sort X
Ṗ - remove the right-most
Ḋ - remove the left-most
⁸ - chain's left argument, X
ȯ - logical OR (if we have nothing left use X instead)
Æm - arithmetic mean
Ḥ - double
. - literal half
+ - add
Ḟ - floor
H - halve
$endgroup$
1
$begingroup$
@NickKennedy 34/5>6.75
$endgroup$
– Jonathan Allan
5 hours ago
1
$begingroup$
Sorry meant1,10,7,7,7,6where 27/4 = 6.75
$endgroup$
– Nick Kennedy
3 hours ago
add a comment
|
$begingroup$
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!
$endgroup$
$begingroup$
Ḟseems to produce the wrong result for[6.5,9].
$endgroup$
– Unrelated String
7 hours ago
1
$begingroup$
@UnrelatedString At the moment I posted this, it was the correct output. Looks like OP has changed the rule now.
$endgroup$
– Erik the Outgolfer
7 hours ago
1
$begingroup$
Yes, I made a mess, sorry :(
$endgroup$
– JuanCa
7 hours ago
1
$begingroup$
As per my comment under Arnauld's post I basically had this algorithm too, so, after getting clarification on the rules, I've posted mine :)
$endgroup$
– Jonathan Allan
7 hours ago
1
$begingroup$
@JonathanAllan Which is the same as Unrelated String's. :P
$endgroup$
– Erik the Outgolfer
7 hours ago
|
show 1 more comment
$begingroup$
Brachylog, 19 bytes
o{bṀk|}⟨+/l⟩×₄<÷₂/₂
Try it online!
And I thought the rounding was awkward in Jelly!
$endgroup$
1
$begingroup$
This is incorrect for[1,10,7,7,7,6]; 27/4 = 6.75 which should round to 6.5 according to spec.
$endgroup$
– Nick Kennedy
3 hours ago
add a comment
|
$begingroup$
JavaScript (V8), 211 bytes
Edit: -2 bytes because I ended with ;n} when I could just end with a }, silly mistake.
a=>{l=_=>a.length
s=i=>a.splice(i,1)
e=_=>a.reduce((t,i)=>t+=i)/l()
g=_=>(a.sort((x,y)=>x-y),s(0),s(-1),e())
t=n=>Math.floor(n)
r=n=>(m=n%1,m<0.75?(m>0.25?t(n)+0.5:t(n)):Math.ceil(n))
return l()>2?r(g()):r(e())}
Try it online!
I'm sure it can be improved as I'm fairly new, but it was fun to solve this one. I believe the main things that could be improved are my rounding logic/methods, and the fact that the main function uses a function body ({ } and return).
There was one thing in the question that was inconsistent with the examples and I wasn't really sure how to handle it. I implemented it so that it's consistent with the examples, but it doesn't exactly reflect the specified rounding rules, here is the example I found to be inconsistent:
6.5, 9 -> 8
You say it should be 8, although the average is 7.75. In the rounding rules you say it has to be at least .76 to go +1. I chose to reflect the examples instead of your rounding rules, so >=0.75 to go +1, and <=0.25 to go -1, between 0.25 and 0.75 (exclusive) for .5.
Slightly ungolfed with explanation:
a => { // a is the input array
l = _=>a.length; // shortcut to get arr length
s = i=>a.splice(i, 1); // shortcut to splice i
e = _=>a.reduce((t, i) => t += i) / l(); // get array avg
g = _=>(a.sort((x,y)=>x-y), s(0), s(-1), e()); // what to execute when > 2: sort, remove 1st/last, get avg
t = n=>Math.floor(n); // Math.floor shortcut
// apply olympic rounding to number by checking the value of n%1
r = n=>(m=n%1,m < 0.75 ? (m > 0.25 ? t(n) + 0.5 : t(n)) : Math.ceil(n));
return l() > 2 ? r(g()) : r(e());
}
New contributor
Matsyir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
1
$begingroup$
I’ve posted a comment on the question about the discrepancy between the example and spec.
$endgroup$
– Nick Kennedy
3 hours ago
add a comment
|
$begingroup$
Swift, 203 bytes
func a(b:[Double])->Void{var r=0.0,h=0.0,l=11.0
b.forEach{(c)in h=c>h ?c:h;l=c<l ?c:l;r+=c}
var d=Double(b.count)
r=d>2 ?(r-h-l)/(d-2.0):r/d
d=Double(Int(r))
r=r-d<=0.25 ?d:r-d<=0.75 ?d+0.5:d+1
print(r)}
Try it online!
$endgroup$
add a comment
|
$begingroup$
J, 36 35 bytes
[:(1r4<.@+&.+:+/%#)}:@}.^:(2<#)@/:~
Try it online!
Borrowed the double / floor / halve trick for rounding to 0.5 increments from Unrelated String.
$endgroup$
add a comment
|
$begingroup$
Retina, 86 bytes
.5
__
d+
*4*__
O`_+
_+ (.+) _+
$1
O`.
^ *
$.&*__:
(_+):(1{4})*(11)?_*
$#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})*(11)?_*
$#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.
$endgroup$
add a comment
|
$begingroup$
PHP, 110 bytes
Seems like PHP has some good built-in functions for this. I just array_sum the whole thing, then if there's more than two elements, subtract the min() and max() values and divide by 2 less than the length of the array.
For the rounding, I use the round() function with the PHP_ROUND_HALF_DOWN flag (which = 2) on double the average, and then divide it by 2 so it goes in increments of 0.5
EDIT: for the case of [6.5, 9] I'm following the stated rule that 7.75 rounds to 7.5 and not 8 like in the original example given.
function s($s){$c=count($s);$t=array_sum($s);if($c>2){$c-=2;$t-=min($s)+max($s);}return round($t/$c*2,0,2)/2;}
Try it online!
$endgroup$
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "200"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
JuanCa is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f192803%2folympic-game-scoring%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
9 Answers
9
active
oldest
votes
9 Answers
9
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
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.
$endgroup$
$begingroup$
Just so happens to accidentally comply with the update to the spec
$endgroup$
– Unrelated String
7 hours ago
$begingroup$
@NickKennedy If I don't round, that case produces 6.8, which should round up to 7 according to the spec since 6.75 < 6.8 ≤ 7.
$endgroup$
– Unrelated String
5 hours ago
1
$begingroup$
sorry one two many 7s. I meant[1,10,6,7,7,7]
$endgroup$
– Nick Kennedy
3 hours ago
1
$begingroup$
Oh, yeah, it does do that one wrong.
$endgroup$
– Unrelated String
3 hours ago
add a comment
|
$begingroup$
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.
$endgroup$
$begingroup$
Just so happens to accidentally comply with the update to the spec
$endgroup$
– Unrelated String
7 hours ago
$begingroup$
@NickKennedy If I don't round, that case produces 6.8, which should round up to 7 according to the spec since 6.75 < 6.8 ≤ 7.
$endgroup$
– Unrelated String
5 hours ago
1
$begingroup$
sorry one two many 7s. I meant[1,10,6,7,7,7]
$endgroup$
– Nick Kennedy
3 hours ago
1
$begingroup$
Oh, yeah, it does do that one wrong.
$endgroup$
– Unrelated String
3 hours ago
add a comment
|
$begingroup$
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.
$endgroup$
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.
edited 7 hours ago
answered 7 hours ago
Unrelated StringUnrelated String
3,7272 gold badges3 silver badges21 bronze badges
3,7272 gold badges3 silver badges21 bronze badges
$begingroup$
Just so happens to accidentally comply with the update to the spec
$endgroup$
– Unrelated String
7 hours ago
$begingroup$
@NickKennedy If I don't round, that case produces 6.8, which should round up to 7 according to the spec since 6.75 < 6.8 ≤ 7.
$endgroup$
– Unrelated String
5 hours ago
1
$begingroup$
sorry one two many 7s. I meant[1,10,6,7,7,7]
$endgroup$
– Nick Kennedy
3 hours ago
1
$begingroup$
Oh, yeah, it does do that one wrong.
$endgroup$
– Unrelated String
3 hours ago
add a comment
|
$begingroup$
Just so happens to accidentally comply with the update to the spec
$endgroup$
– Unrelated String
7 hours ago
$begingroup$
@NickKennedy If I don't round, that case produces 6.8, which should round up to 7 according to the spec since 6.75 < 6.8 ≤ 7.
$endgroup$
– Unrelated String
5 hours ago
1
$begingroup$
sorry one two many 7s. I meant[1,10,6,7,7,7]
$endgroup$
– Nick Kennedy
3 hours ago
1
$begingroup$
Oh, yeah, it does do that one wrong.
$endgroup$
– Unrelated String
3 hours ago
$begingroup$
Just so happens to accidentally comply with the update to the spec
$endgroup$
– Unrelated String
7 hours ago
$begingroup$
Just so happens to accidentally comply with the update to the spec
$endgroup$
– Unrelated String
7 hours ago
$begingroup$
@NickKennedy If I don't round, that case produces 6.8, which should round up to 7 according to the spec since 6.75 < 6.8 ≤ 7.
$endgroup$
– Unrelated String
5 hours ago
$begingroup$
@NickKennedy If I don't round, that case produces 6.8, which should round up to 7 according to the spec since 6.75 < 6.8 ≤ 7.
$endgroup$
– Unrelated String
5 hours ago
1
1
$begingroup$
sorry one two many 7s. I meant
[1,10,6,7,7,7]$endgroup$
– Nick Kennedy
3 hours ago
$begingroup$
sorry one two many 7s. I meant
[1,10,6,7,7,7]$endgroup$
– Nick Kennedy
3 hours ago
1
1
$begingroup$
Oh, yeah, it does do that one wrong.
$endgroup$
– Unrelated String
3 hours ago
$begingroup$
Oh, yeah, it does do that one wrong.
$endgroup$
– Unrelated String
3 hours ago
add a comment
|
$begingroup$
Jelly, 12 bytes
ṢṖḊȯ⁸ÆmḤ+.ḞH
A monadic Link accepting a list of numbers which yields a number.
Try it online!
How?
ṢṖḊȯ⁸ÆmḤ+.ḞH - Link, list of numbers, X
Ṣ - sort X
Ṗ - remove the right-most
Ḋ - remove the left-most
⁸ - chain's left argument, X
ȯ - logical OR (if we have nothing left use X instead)
Æm - arithmetic mean
Ḥ - double
. - literal half
+ - add
Ḟ - floor
H - halve
$endgroup$
1
$begingroup$
@NickKennedy 34/5>6.75
$endgroup$
– Jonathan Allan
5 hours ago
1
$begingroup$
Sorry meant1,10,7,7,7,6where 27/4 = 6.75
$endgroup$
– Nick Kennedy
3 hours ago
add a comment
|
$begingroup$
Jelly, 12 bytes
ṢṖḊȯ⁸ÆmḤ+.ḞH
A monadic Link accepting a list of numbers which yields a number.
Try it online!
How?
ṢṖḊȯ⁸ÆmḤ+.ḞH - Link, list of numbers, X
Ṣ - sort X
Ṗ - remove the right-most
Ḋ - remove the left-most
⁸ - chain's left argument, X
ȯ - logical OR (if we have nothing left use X instead)
Æm - arithmetic mean
Ḥ - double
. - literal half
+ - add
Ḟ - floor
H - halve
$endgroup$
1
$begingroup$
@NickKennedy 34/5>6.75
$endgroup$
– Jonathan Allan
5 hours ago
1
$begingroup$
Sorry meant1,10,7,7,7,6where 27/4 = 6.75
$endgroup$
– Nick Kennedy
3 hours ago
add a comment
|
$begingroup$
Jelly, 12 bytes
ṢṖḊȯ⁸ÆmḤ+.ḞH
A monadic Link accepting a list of numbers which yields a number.
Try it online!
How?
ṢṖḊȯ⁸ÆmḤ+.ḞH - Link, list of numbers, X
Ṣ - sort X
Ṗ - remove the right-most
Ḋ - remove the left-most
⁸ - chain's left argument, X
ȯ - logical OR (if we have nothing left use X instead)
Æm - arithmetic mean
Ḥ - double
. - literal half
+ - add
Ḟ - floor
H - halve
$endgroup$
Jelly, 12 bytes
ṢṖḊȯ⁸ÆmḤ+.ḞH
A monadic Link accepting a list of numbers which yields a number.
Try it online!
How?
ṢṖḊȯ⁸ÆmḤ+.ḞH - Link, list of numbers, X
Ṣ - sort X
Ṗ - remove the right-most
Ḋ - remove the left-most
⁸ - chain's left argument, X
ȯ - logical OR (if we have nothing left use X instead)
Æm - arithmetic mean
Ḥ - double
. - literal half
+ - add
Ḟ - floor
H - halve
edited 7 hours ago
answered 7 hours ago
Jonathan AllanJonathan Allan
60.2k5 gold badges44 silver badges187 bronze badges
60.2k5 gold badges44 silver badges187 bronze badges
1
$begingroup$
@NickKennedy 34/5>6.75
$endgroup$
– Jonathan Allan
5 hours ago
1
$begingroup$
Sorry meant1,10,7,7,7,6where 27/4 = 6.75
$endgroup$
– Nick Kennedy
3 hours ago
add a comment
|
1
$begingroup$
@NickKennedy 34/5>6.75
$endgroup$
– Jonathan Allan
5 hours ago
1
$begingroup$
Sorry meant1,10,7,7,7,6where 27/4 = 6.75
$endgroup$
– Nick Kennedy
3 hours ago
1
1
$begingroup$
@NickKennedy 34/5>6.75
$endgroup$
– Jonathan Allan
5 hours ago
$begingroup$
@NickKennedy 34/5>6.75
$endgroup$
– Jonathan Allan
5 hours ago
1
1
$begingroup$
Sorry meant
1,10,7,7,7,6 where 27/4 = 6.75$endgroup$
– Nick Kennedy
3 hours ago
$begingroup$
Sorry meant
1,10,7,7,7,6 where 27/4 = 6.75$endgroup$
– Nick Kennedy
3 hours ago
add a comment
|
$begingroup$
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!
$endgroup$
$begingroup$
Ḟseems to produce the wrong result for[6.5,9].
$endgroup$
– Unrelated String
7 hours ago
1
$begingroup$
@UnrelatedString At the moment I posted this, it was the correct output. Looks like OP has changed the rule now.
$endgroup$
– Erik the Outgolfer
7 hours ago
1
$begingroup$
Yes, I made a mess, sorry :(
$endgroup$
– JuanCa
7 hours ago
1
$begingroup$
As per my comment under Arnauld's post I basically had this algorithm too, so, after getting clarification on the rules, I've posted mine :)
$endgroup$
– Jonathan Allan
7 hours ago
1
$begingroup$
@JonathanAllan Which is the same as Unrelated String's. :P
$endgroup$
– Erik the Outgolfer
7 hours ago
|
show 1 more comment
$begingroup$
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!
$endgroup$
$begingroup$
Ḟseems to produce the wrong result for[6.5,9].
$endgroup$
– Unrelated String
7 hours ago
1
$begingroup$
@UnrelatedString At the moment I posted this, it was the correct output. Looks like OP has changed the rule now.
$endgroup$
– Erik the Outgolfer
7 hours ago
1
$begingroup$
Yes, I made a mess, sorry :(
$endgroup$
– JuanCa
7 hours ago
1
$begingroup$
As per my comment under Arnauld's post I basically had this algorithm too, so, after getting clarification on the rules, I've posted mine :)
$endgroup$
– Jonathan Allan
7 hours ago
1
$begingroup$
@JonathanAllan Which is the same as Unrelated String's. :P
$endgroup$
– Erik the Outgolfer
7 hours ago
|
show 1 more comment
$begingroup$
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!
$endgroup$
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!
edited 7 hours ago
answered 7 hours ago
Erik the OutgolferErik the Outgolfer
36.3k4 gold badges30 silver badges113 bronze badges
36.3k4 gold badges30 silver badges113 bronze badges
$begingroup$
Ḟseems to produce the wrong result for[6.5,9].
$endgroup$
– Unrelated String
7 hours ago
1
$begingroup$
@UnrelatedString At the moment I posted this, it was the correct output. Looks like OP has changed the rule now.
$endgroup$
– Erik the Outgolfer
7 hours ago
1
$begingroup$
Yes, I made a mess, sorry :(
$endgroup$
– JuanCa
7 hours ago
1
$begingroup$
As per my comment under Arnauld's post I basically had this algorithm too, so, after getting clarification on the rules, I've posted mine :)
$endgroup$
– Jonathan Allan
7 hours ago
1
$begingroup$
@JonathanAllan Which is the same as Unrelated String's. :P
$endgroup$
– Erik the Outgolfer
7 hours ago
|
show 1 more comment
$begingroup$
Ḟseems to produce the wrong result for[6.5,9].
$endgroup$
– Unrelated String
7 hours ago
1
$begingroup$
@UnrelatedString At the moment I posted this, it was the correct output. Looks like OP has changed the rule now.
$endgroup$
– Erik the Outgolfer
7 hours ago
1
$begingroup$
Yes, I made a mess, sorry :(
$endgroup$
– JuanCa
7 hours ago
1
$begingroup$
As per my comment under Arnauld's post I basically had this algorithm too, so, after getting clarification on the rules, I've posted mine :)
$endgroup$
– Jonathan Allan
7 hours ago
1
$begingroup$
@JonathanAllan Which is the same as Unrelated String's. :P
$endgroup$
– Erik the Outgolfer
7 hours ago
$begingroup$
Ḟ seems to produce the wrong result for [6.5,9].$endgroup$
– Unrelated String
7 hours ago
$begingroup$
Ḟ seems to produce the wrong result for [6.5,9].$endgroup$
– Unrelated String
7 hours ago
1
1
$begingroup$
@UnrelatedString At the moment I posted this, it was the correct output. Looks like OP has changed the rule now.
$endgroup$
– Erik the Outgolfer
7 hours ago
$begingroup$
@UnrelatedString At the moment I posted this, it was the correct output. Looks like OP has changed the rule now.
$endgroup$
– Erik the Outgolfer
7 hours ago
1
1
$begingroup$
Yes, I made a mess, sorry :(
$endgroup$
– JuanCa
7 hours ago
$begingroup$
Yes, I made a mess, sorry :(
$endgroup$
– JuanCa
7 hours ago
1
1
$begingroup$
As per my comment under Arnauld's post I basically had this algorithm too, so, after getting clarification on the rules, I've posted mine :)
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
As per my comment under Arnauld's post I basically had this algorithm too, so, after getting clarification on the rules, I've posted mine :)
$endgroup$
– Jonathan Allan
7 hours ago
1
1
$begingroup$
@JonathanAllan Which is the same as Unrelated String's. :P
$endgroup$
– Erik the Outgolfer
7 hours ago
$begingroup$
@JonathanAllan Which is the same as Unrelated String's. :P
$endgroup$
– Erik the Outgolfer
7 hours ago
|
show 1 more comment
$begingroup$
Brachylog, 19 bytes
o{bṀk|}⟨+/l⟩×₄<÷₂/₂
Try it online!
And I thought the rounding was awkward in Jelly!
$endgroup$
1
$begingroup$
This is incorrect for[1,10,7,7,7,6]; 27/4 = 6.75 which should round to 6.5 according to spec.
$endgroup$
– Nick Kennedy
3 hours ago
add a comment
|
$begingroup$
Brachylog, 19 bytes
o{bṀk|}⟨+/l⟩×₄<÷₂/₂
Try it online!
And I thought the rounding was awkward in Jelly!
$endgroup$
1
$begingroup$
This is incorrect for[1,10,7,7,7,6]; 27/4 = 6.75 which should round to 6.5 according to spec.
$endgroup$
– Nick Kennedy
3 hours ago
add a comment
|
$begingroup$
Brachylog, 19 bytes
o{bṀk|}⟨+/l⟩×₄<÷₂/₂
Try it online!
And I thought the rounding was awkward in Jelly!
$endgroup$
Brachylog, 19 bytes
o{bṀk|}⟨+/l⟩×₄<÷₂/₂
Try it online!
And I thought the rounding was awkward in Jelly!
answered 7 hours ago
Unrelated StringUnrelated String
3,7272 gold badges3 silver badges21 bronze badges
3,7272 gold badges3 silver badges21 bronze badges
1
$begingroup$
This is incorrect for[1,10,7,7,7,6]; 27/4 = 6.75 which should round to 6.5 according to spec.
$endgroup$
– Nick Kennedy
3 hours ago
add a comment
|
1
$begingroup$
This is incorrect for[1,10,7,7,7,6]; 27/4 = 6.75 which should round to 6.5 according to spec.
$endgroup$
– Nick Kennedy
3 hours ago
1
1
$begingroup$
This is incorrect for
[1,10,7,7,7,6]; 27/4 = 6.75 which should round to 6.5 according to spec.$endgroup$
– Nick Kennedy
3 hours ago
$begingroup$
This is incorrect for
[1,10,7,7,7,6]; 27/4 = 6.75 which should round to 6.5 according to spec.$endgroup$
– Nick Kennedy
3 hours ago
add a comment
|
$begingroup$
JavaScript (V8), 211 bytes
Edit: -2 bytes because I ended with ;n} when I could just end with a }, silly mistake.
a=>{l=_=>a.length
s=i=>a.splice(i,1)
e=_=>a.reduce((t,i)=>t+=i)/l()
g=_=>(a.sort((x,y)=>x-y),s(0),s(-1),e())
t=n=>Math.floor(n)
r=n=>(m=n%1,m<0.75?(m>0.25?t(n)+0.5:t(n)):Math.ceil(n))
return l()>2?r(g()):r(e())}
Try it online!
I'm sure it can be improved as I'm fairly new, but it was fun to solve this one. I believe the main things that could be improved are my rounding logic/methods, and the fact that the main function uses a function body ({ } and return).
There was one thing in the question that was inconsistent with the examples and I wasn't really sure how to handle it. I implemented it so that it's consistent with the examples, but it doesn't exactly reflect the specified rounding rules, here is the example I found to be inconsistent:
6.5, 9 -> 8
You say it should be 8, although the average is 7.75. In the rounding rules you say it has to be at least .76 to go +1. I chose to reflect the examples instead of your rounding rules, so >=0.75 to go +1, and <=0.25 to go -1, between 0.25 and 0.75 (exclusive) for .5.
Slightly ungolfed with explanation:
a => { // a is the input array
l = _=>a.length; // shortcut to get arr length
s = i=>a.splice(i, 1); // shortcut to splice i
e = _=>a.reduce((t, i) => t += i) / l(); // get array avg
g = _=>(a.sort((x,y)=>x-y), s(0), s(-1), e()); // what to execute when > 2: sort, remove 1st/last, get avg
t = n=>Math.floor(n); // Math.floor shortcut
// apply olympic rounding to number by checking the value of n%1
r = n=>(m=n%1,m < 0.75 ? (m > 0.25 ? t(n) + 0.5 : t(n)) : Math.ceil(n));
return l() > 2 ? r(g()) : r(e());
}
New contributor
Matsyir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
1
$begingroup$
I’ve posted a comment on the question about the discrepancy between the example and spec.
$endgroup$
– Nick Kennedy
3 hours ago
add a comment
|
$begingroup$
JavaScript (V8), 211 bytes
Edit: -2 bytes because I ended with ;n} when I could just end with a }, silly mistake.
a=>{l=_=>a.length
s=i=>a.splice(i,1)
e=_=>a.reduce((t,i)=>t+=i)/l()
g=_=>(a.sort((x,y)=>x-y),s(0),s(-1),e())
t=n=>Math.floor(n)
r=n=>(m=n%1,m<0.75?(m>0.25?t(n)+0.5:t(n)):Math.ceil(n))
return l()>2?r(g()):r(e())}
Try it online!
I'm sure it can be improved as I'm fairly new, but it was fun to solve this one. I believe the main things that could be improved are my rounding logic/methods, and the fact that the main function uses a function body ({ } and return).
There was one thing in the question that was inconsistent with the examples and I wasn't really sure how to handle it. I implemented it so that it's consistent with the examples, but it doesn't exactly reflect the specified rounding rules, here is the example I found to be inconsistent:
6.5, 9 -> 8
You say it should be 8, although the average is 7.75. In the rounding rules you say it has to be at least .76 to go +1. I chose to reflect the examples instead of your rounding rules, so >=0.75 to go +1, and <=0.25 to go -1, between 0.25 and 0.75 (exclusive) for .5.
Slightly ungolfed with explanation:
a => { // a is the input array
l = _=>a.length; // shortcut to get arr length
s = i=>a.splice(i, 1); // shortcut to splice i
e = _=>a.reduce((t, i) => t += i) / l(); // get array avg
g = _=>(a.sort((x,y)=>x-y), s(0), s(-1), e()); // what to execute when > 2: sort, remove 1st/last, get avg
t = n=>Math.floor(n); // Math.floor shortcut
// apply olympic rounding to number by checking the value of n%1
r = n=>(m=n%1,m < 0.75 ? (m > 0.25 ? t(n) + 0.5 : t(n)) : Math.ceil(n));
return l() > 2 ? r(g()) : r(e());
}
New contributor
Matsyir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
1
$begingroup$
I’ve posted a comment on the question about the discrepancy between the example and spec.
$endgroup$
– Nick Kennedy
3 hours ago
add a comment
|
$begingroup$
JavaScript (V8), 211 bytes
Edit: -2 bytes because I ended with ;n} when I could just end with a }, silly mistake.
a=>{l=_=>a.length
s=i=>a.splice(i,1)
e=_=>a.reduce((t,i)=>t+=i)/l()
g=_=>(a.sort((x,y)=>x-y),s(0),s(-1),e())
t=n=>Math.floor(n)
r=n=>(m=n%1,m<0.75?(m>0.25?t(n)+0.5:t(n)):Math.ceil(n))
return l()>2?r(g()):r(e())}
Try it online!
I'm sure it can be improved as I'm fairly new, but it was fun to solve this one. I believe the main things that could be improved are my rounding logic/methods, and the fact that the main function uses a function body ({ } and return).
There was one thing in the question that was inconsistent with the examples and I wasn't really sure how to handle it. I implemented it so that it's consistent with the examples, but it doesn't exactly reflect the specified rounding rules, here is the example I found to be inconsistent:
6.5, 9 -> 8
You say it should be 8, although the average is 7.75. In the rounding rules you say it has to be at least .76 to go +1. I chose to reflect the examples instead of your rounding rules, so >=0.75 to go +1, and <=0.25 to go -1, between 0.25 and 0.75 (exclusive) for .5.
Slightly ungolfed with explanation:
a => { // a is the input array
l = _=>a.length; // shortcut to get arr length
s = i=>a.splice(i, 1); // shortcut to splice i
e = _=>a.reduce((t, i) => t += i) / l(); // get array avg
g = _=>(a.sort((x,y)=>x-y), s(0), s(-1), e()); // what to execute when > 2: sort, remove 1st/last, get avg
t = n=>Math.floor(n); // Math.floor shortcut
// apply olympic rounding to number by checking the value of n%1
r = n=>(m=n%1,m < 0.75 ? (m > 0.25 ? t(n) + 0.5 : t(n)) : Math.ceil(n));
return l() > 2 ? r(g()) : r(e());
}
New contributor
Matsyir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
JavaScript (V8), 211 bytes
Edit: -2 bytes because I ended with ;n} when I could just end with a }, silly mistake.
a=>{l=_=>a.length
s=i=>a.splice(i,1)
e=_=>a.reduce((t,i)=>t+=i)/l()
g=_=>(a.sort((x,y)=>x-y),s(0),s(-1),e())
t=n=>Math.floor(n)
r=n=>(m=n%1,m<0.75?(m>0.25?t(n)+0.5:t(n)):Math.ceil(n))
return l()>2?r(g()):r(e())}
Try it online!
I'm sure it can be improved as I'm fairly new, but it was fun to solve this one. I believe the main things that could be improved are my rounding logic/methods, and the fact that the main function uses a function body ({ } and return).
There was one thing in the question that was inconsistent with the examples and I wasn't really sure how to handle it. I implemented it so that it's consistent with the examples, but it doesn't exactly reflect the specified rounding rules, here is the example I found to be inconsistent:
6.5, 9 -> 8
You say it should be 8, although the average is 7.75. In the rounding rules you say it has to be at least .76 to go +1. I chose to reflect the examples instead of your rounding rules, so >=0.75 to go +1, and <=0.25 to go -1, between 0.25 and 0.75 (exclusive) for .5.
Slightly ungolfed with explanation:
a => { // a is the input array
l = _=>a.length; // shortcut to get arr length
s = i=>a.splice(i, 1); // shortcut to splice i
e = _=>a.reduce((t, i) => t += i) / l(); // get array avg
g = _=>(a.sort((x,y)=>x-y), s(0), s(-1), e()); // what to execute when > 2: sort, remove 1st/last, get avg
t = n=>Math.floor(n); // Math.floor shortcut
// apply olympic rounding to number by checking the value of n%1
r = n=>(m=n%1,m < 0.75 ? (m > 0.25 ? t(n) + 0.5 : t(n)) : Math.ceil(n));
return l() > 2 ? r(g()) : r(e());
}
New contributor
Matsyir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 2 hours ago
New contributor
Matsyir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 5 hours ago
MatsyirMatsyir
313 bronze badges
313 bronze badges
New contributor
Matsyir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Matsyir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
$begingroup$
I’ve posted a comment on the question about the discrepancy between the example and spec.
$endgroup$
– Nick Kennedy
3 hours ago
add a comment
|
1
$begingroup$
I’ve posted a comment on the question about the discrepancy between the example and spec.
$endgroup$
– Nick Kennedy
3 hours ago
1
1
$begingroup$
I’ve posted a comment on the question about the discrepancy between the example and spec.
$endgroup$
– Nick Kennedy
3 hours ago
$begingroup$
I’ve posted a comment on the question about the discrepancy between the example and spec.
$endgroup$
– Nick Kennedy
3 hours ago
add a comment
|
$begingroup$
Swift, 203 bytes
func a(b:[Double])->Void{var r=0.0,h=0.0,l=11.0
b.forEach{(c)in h=c>h ?c:h;l=c<l ?c:l;r+=c}
var d=Double(b.count)
r=d>2 ?(r-h-l)/(d-2.0):r/d
d=Double(Int(r))
r=r-d<=0.25 ?d:r-d<=0.75 ?d+0.5:d+1
print(r)}
Try it online!
$endgroup$
add a comment
|
$begingroup$
Swift, 203 bytes
func a(b:[Double])->Void{var r=0.0,h=0.0,l=11.0
b.forEach{(c)in h=c>h ?c:h;l=c<l ?c:l;r+=c}
var d=Double(b.count)
r=d>2 ?(r-h-l)/(d-2.0):r/d
d=Double(Int(r))
r=r-d<=0.25 ?d:r-d<=0.75 ?d+0.5:d+1
print(r)}
Try it online!
$endgroup$
add a comment
|
$begingroup$
Swift, 203 bytes
func a(b:[Double])->Void{var r=0.0,h=0.0,l=11.0
b.forEach{(c)in h=c>h ?c:h;l=c<l ?c:l;r+=c}
var d=Double(b.count)
r=d>2 ?(r-h-l)/(d-2.0):r/d
d=Double(Int(r))
r=r-d<=0.25 ?d:r-d<=0.75 ?d+0.5:d+1
print(r)}
Try it online!
$endgroup$
Swift, 203 bytes
func a(b:[Double])->Void{var r=0.0,h=0.0,l=11.0
b.forEach{(c)in h=c>h ?c:h;l=c<l ?c:l;r+=c}
var d=Double(b.count)
r=d>2 ?(r-h-l)/(d-2.0):r/d
d=Double(Int(r))
r=r-d<=0.25 ?d:r-d<=0.75 ?d+0.5:d+1
print(r)}
Try it online!
answered 5 hours ago
onnowebonnoweb
1813 bronze badges
1813 bronze badges
add a comment
|
add a comment
|
$begingroup$
J, 36 35 bytes
[:(1r4<.@+&.+:+/%#)}:@}.^:(2<#)@/:~
Try it online!
Borrowed the double / floor / halve trick for rounding to 0.5 increments from Unrelated String.
$endgroup$
add a comment
|
$begingroup$
J, 36 35 bytes
[:(1r4<.@+&.+:+/%#)}:@}.^:(2<#)@/:~
Try it online!
Borrowed the double / floor / halve trick for rounding to 0.5 increments from Unrelated String.
$endgroup$
add a comment
|
$begingroup$
J, 36 35 bytes
[:(1r4<.@+&.+:+/%#)}:@}.^:(2<#)@/:~
Try it online!
Borrowed the double / floor / halve trick for rounding to 0.5 increments from Unrelated String.
$endgroup$
J, 36 35 bytes
[:(1r4<.@+&.+:+/%#)}:@}.^:(2<#)@/:~
Try it online!
Borrowed the double / floor / halve trick for rounding to 0.5 increments from Unrelated String.
answered 3 hours ago
JonahJonah
4,7522 gold badges12 silver badges22 bronze badges
4,7522 gold badges12 silver badges22 bronze badges
add a comment
|
add a comment
|
$begingroup$
Retina, 86 bytes
.5
__
d+
*4*__
O`_+
_+ (.+) _+
$1
O`.
^ *
$.&*__:
(_+):(1{4})*(11)?_*
$#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})*(11)?_*
$#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.
$endgroup$
add a comment
|
$begingroup$
Retina, 86 bytes
.5
__
d+
*4*__
O`_+
_+ (.+) _+
$1
O`.
^ *
$.&*__:
(_+):(1{4})*(11)?_*
$#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})*(11)?_*
$#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.
$endgroup$
add a comment
|
$begingroup$
Retina, 86 bytes
.5
__
d+
*4*__
O`_+
_+ (.+) _+
$1
O`.
^ *
$.&*__:
(_+):(1{4})*(11)?_*
$#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})*(11)?_*
$#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.
$endgroup$
Retina, 86 bytes
.5
__
d+
*4*__
O`_+
_+ (.+) _+
$1
O`.
^ *
$.&*__:
(_+):(1{4})*(11)?_*
$#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})*(11)?_*
$#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.
answered 2 hours ago
NeilNeil
88.8k8 gold badges46 silver badges188 bronze badges
88.8k8 gold badges46 silver badges188 bronze badges
add a comment
|
add a comment
|
$begingroup$
PHP, 110 bytes
Seems like PHP has some good built-in functions for this. I just array_sum the whole thing, then if there's more than two elements, subtract the min() and max() values and divide by 2 less than the length of the array.
For the rounding, I use the round() function with the PHP_ROUND_HALF_DOWN flag (which = 2) on double the average, and then divide it by 2 so it goes in increments of 0.5
EDIT: for the case of [6.5, 9] I'm following the stated rule that 7.75 rounds to 7.5 and not 8 like in the original example given.
function s($s){$c=count($s);$t=array_sum($s);if($c>2){$c-=2;$t-=min($s)+max($s);}return round($t/$c*2,0,2)/2;}
Try it online!
$endgroup$
add a comment
|
$begingroup$
PHP, 110 bytes
Seems like PHP has some good built-in functions for this. I just array_sum the whole thing, then if there's more than two elements, subtract the min() and max() values and divide by 2 less than the length of the array.
For the rounding, I use the round() function with the PHP_ROUND_HALF_DOWN flag (which = 2) on double the average, and then divide it by 2 so it goes in increments of 0.5
EDIT: for the case of [6.5, 9] I'm following the stated rule that 7.75 rounds to 7.5 and not 8 like in the original example given.
function s($s){$c=count($s);$t=array_sum($s);if($c>2){$c-=2;$t-=min($s)+max($s);}return round($t/$c*2,0,2)/2;}
Try it online!
$endgroup$
add a comment
|
$begingroup$
PHP, 110 bytes
Seems like PHP has some good built-in functions for this. I just array_sum the whole thing, then if there's more than two elements, subtract the min() and max() values and divide by 2 less than the length of the array.
For the rounding, I use the round() function with the PHP_ROUND_HALF_DOWN flag (which = 2) on double the average, and then divide it by 2 so it goes in increments of 0.5
EDIT: for the case of [6.5, 9] I'm following the stated rule that 7.75 rounds to 7.5 and not 8 like in the original example given.
function s($s){$c=count($s);$t=array_sum($s);if($c>2){$c-=2;$t-=min($s)+max($s);}return round($t/$c*2,0,2)/2;}
Try it online!
$endgroup$
PHP, 110 bytes
Seems like PHP has some good built-in functions for this. I just array_sum the whole thing, then if there's more than two elements, subtract the min() and max() values and divide by 2 less than the length of the array.
For the rounding, I use the round() function with the PHP_ROUND_HALF_DOWN flag (which = 2) on double the average, and then divide it by 2 so it goes in increments of 0.5
EDIT: for the case of [6.5, 9] I'm following the stated rule that 7.75 rounds to 7.5 and not 8 like in the original example given.
function s($s){$c=count($s);$t=array_sum($s);if($c>2){$c-=2;$t-=min($s)+max($s);}return round($t/$c*2,0,2)/2;}
Try it online!
edited 1 hour ago
answered 1 hour ago
XMarkXMark
713 bronze badges
713 bronze badges
add a comment
|
add a comment
|
JuanCa is a new contributor. Be nice, and check out our Code of Conduct.
JuanCa is a new contributor. Be nice, and check out our Code of Conduct.
JuanCa is a new contributor. Be nice, and check out our Code of Conduct.
JuanCa is a new contributor. Be nice, and check out our Code of Conduct.
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f192803%2folympic-game-scoring%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
$begingroup$
How is the second example (6.5, 9 => 8) valid? If you throw out the high and the low, there are no values left to average?
$endgroup$
– Jeff Zeitlin
8 hours ago
4
$begingroup$
I'd suggest we do not handle invalid input, the Olympics will have a fixed number of judges greater than two for such an event. (Diving removes the four extremities from seven for example)
$endgroup$
– Jonathan Allan
8 hours ago
2
$begingroup$
Ah, we have to special case when given two judge's scores, that's a little odd.
$endgroup$
– Jonathan Allan
7 hours ago
2
$begingroup$
Are we to use round-half-up rounding - for example
[5, 6, 6, 10, 11, 13]leads to an average of8.25, should we output8.0or8.5?$endgroup$
– Jonathan Allan
7 hours ago
2
$begingroup$
Your example
6.5, 9disagrees with your spec which indicates that x.75 rounds to x.5.$endgroup$
– Nick Kennedy
3 hours ago