Ad
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    O_o

  • Custom User Avatar

    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).

  • Custom User Avatar

    Alternatively, why not ensure there are at least 2 values in the array?

  • Custom User Avatar

    Ok, i messed up the second one.
    But how about

    sum(Z) = 0 + (1 + -1) + (2 + -2) + (3 + -3) + ...
    

    Anyway i am not a mathematician, just put it in the description then no one will be confused.

  • Custom User Avatar

    Correct me if I am wrong

  • Custom User Avatar

    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.

  • Custom User Avatar

    Then we got new issues.

    • You are expecting NaN from input new int[]{} which is not mentioned in the description. (why cannot it be 0 because all integer n ∈ Z match the requirement mean([n]) = n = median([n]), and the sum would be 0 i guess)
    • You are expecting NaN from input new int[]{x} which should be put in the description as well. (why cannot it x because mean([x,x]) = x = median([x,x]))
  • Custom User Avatar

    I thought you'd have already accounted for it in the beginning ;-)

  • Custom User Avatar

    Confirmed.

  • Custom User Avatar

    Fixed it.

  • Custom User Avatar

    Why it is

    testing(MeanEqualsMedian.findSum(new int[]{-85,-64,4,14,23,36,97}),160.0,0)
    

    The only possible n is 123
    Accoring to my solution, there are two more potential n -10.333333333333333 and 47.0 but if you put them back into to the array, the mean is not equals to the median

  • Custom User Avatar

    Interesting! Very nice!

  • Custom User Avatar

    This one is for java unlike the other one.

    In that case you should submit a Java translation to the existing Kata instead of authoring and publishing a duplicate Kata.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Loading more items...