Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
O_o
I considered that before, but then it would lose some of the "spice" in the question. I wanted to get some number theory in the problem, but since I'm not a mathematician, it's hard for me to get correct answers eg. if you add up all postive and negative integers would it be 0 or NaN?
ZED.CWT, your approach makes sense but my approach makes sense as well, like I said I'm not a mathematician either so I'm not sure which one is correct.
I added in the description to return NaN if all integers would work as n to clear things up(and make things a little more boring).
Alternatively, why not ensure there are at least 2 values in the array?
Ok, i messed up the second one.
But how about
Anyway i am not a mathematician, just put it in the description then no one will be confused.
Correct me if I am wrong
For both cases, new int[]{} and new int[]{x}, any integer would be able to work as n to satisfy the requirements. This means that we have to take the sum of all integers ranging from negative infinity to postive infinity. Taking the sum of all postive integers is postive infinity. Likewise, taking the sum of all negative integers is negative infinity. Postive infinity plus negative infinity is indeterminate, so NaN would best represent that.
Then we got new issues.
NaN
from inputnew int[]{}
which is not mentioned in the description. (why cannot it be0
because all integern ∈ Z
match the requirementmean([n]) = n = median([n])
, and the sum would be0
i guess)NaN
from inputnew int[]{x}
which should be put in the description as well. (why cannot itx
becausemean([x,x]) = x = median([x,x])
)I thought you'd have already accounted for it in the beginning ;-)
Confirmed.
Fixed it.
Why it is
The only possible n is 123
Accoring to my solution, there are two more potential n
-10.333333333333333
and47.0
but if you put them back into to the array, the mean is not equals to the medianInteresting! Very nice!
In that case you should submit a Java translation to the existing Kata instead of authoring and publishing a duplicate Kata.
This comment is hidden because it contains spoiler information about the solution
Loading more items...