Ad
  • Custom User Avatar

    First element of the array should be 0; you had -6. So your code is wrong.
    hint: operator precedence.

  • Custom User Avatar

    45762893920 is bigger than Integer.MAX_VALUE and java can't use it as an int. You have to tell java to treat it as a long by adding an L
    45762893920L will work.

  • Custom User Avatar

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

  • Custom User Avatar

    It fails since digitize(0L) will return an empty array instead of returning {0}

  • Custom User Avatar

    Thanks for introducing me to the stream methods available, really nice pattern.

  • Custom User Avatar

    Approved by author secretly

  • Custom User Avatar

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

  • Custom User Avatar

    I agree that the division introduces a loss of precision, that is the problem when calculating with floating numbers. And that's why it is recommended to compare doubles with an offset.

    Mathematically
    (navg - (sum / newSize)) * newSize and navg * newSize - sum are the same, the later being the simplified version. I unfortunately did not saw at first sight that it could be simplified. That was my mistake.

  • Default User Avatar

    I looked at your solution. I am rather sure that the problem comes from your division (division introduces an added error, error "multiplied" by a multiplication) in your calculation of "newAvg". I re-wrote that line and then your solution passes every time.

  • Custom User Avatar

    "navg = 115053.00000000001" is the input, not the result of the function.

    The random tests are failing randomly with my solution.

    The test randomFailure above which I extracted from the tests is failing everytime with my solution.

    I had to modify the testing method like explained above to make it pass.

  • Default User Avatar

    Thanks for your work! I see that you finally passed the kata. The description says:

    The function new_avg(arr, navg) should return the expected donation (rounded up to the next integer) that will permit to reach the average navg.

    The answer must be an integer so I don't see a reason to use a tolerance.
    To get "navg = 115053.00000000001" I suppose that in a first approach you didn't round up(?).

  • Custom User Avatar

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

  • Custom User Avatar

    very good solution, but you could also have used your formatter DTF for the parsing, instead splitting on the PIPE:
    LocalTime.parse(s, DTF).toSecondOfDay

    sorry, I didn't saw that the inputs have randomly 1 or two numbers, so the Formatter can't be used for Parsing; you would need a FORMATTER and a PARSER, where the PARSER will use optional section:

    private static final DateTimeFormatter PARSER = DateTimeFormatter.ofPattern("H[H]|m[m]|s[s]");
    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("HH|mm|ss");
    
  • Custom User Avatar

    Ok, thanks for your reply.
    It's all clear now.

  • Default User Avatar

    Sorry I didn't understand your post.
    When I wrote: Substrings in the input string are separated by , or ," I didn't mean that in each language there would be the two types of separator; I meant that the types could be one or the other depending on the language. It happens that Kotlin has the first type of separator and Swift has the other type. Anyway with a regex (as yo did) the difference is not a problem. I added that sentence after a post from ByteEater that you can see below.

  • Loading more items...