Ad
  • Default User Avatar

    Btw you are 6 kyu by just solving 55 kata, which is rare and impressive.
    Did you already have experience before you started codewars which helped you solve higher kata(more score point) earlier and rank up quickly.

    Or were you beginner and yet you just went ahead and solved higher level kata.

  • Default User Avatar

    @seba_blue I solved it! Ended up with whooping 16 line code due to my stubbornness.

    i got too hung up on the process of customer talking up empty counter. So My sol was to fill the counter and reduce each customer by 1 till got to 0, when at 0 they would be replaced.
    Basically decrement all to 0, each decrement would add 1 to time then return the time.

    Reading top sol made me realize if i had focused just on total time each counter would operate, it would've been easier.
    Exciting kata nonetheless. Cheers!

  • Default User Avatar

    Immediately came to the discussion after understanding that it's a good kata. I wonder how long i will take.

  • Custom User Avatar

    Tests are not ideal but they are correct. It is hard to create randomized tests which catch all possible bugs. Your solution does not work for some simple test cases like this one:

    ( -9.21+ -8.97* -0.00+6.51+(5.50+6.81))
    

    The expected result is 7.263867809057526 but your solution returns -915.278670000000034.

    A simplified version of this test case:

    ( -9+ 8*0+6+(5+6))
    

    Expected: 8, your solution: 799.087999999999965.

  • Custom User Avatar

    Yes, it is always true for Java and for any sane programming language. You still need to be careful with more complicated expressions and if you use a low-level programming language like C with specific compiler flags (e.g., --ffast-math): It is possible that you get different results on different machines even if they are IEEE-754 compliant.

    Historically, the original version of Java was not strict with floating-point arithmetic and it was possible to get different results on different machines (but always the same results on the same machine). That's why Java had the modifier strictfp to make sure that floating-point results are reproducible (it was removed in Java 17).

  • Custom User Avatar

    Sorry for a bit dumb question.

    Does this mean that if I do something like

    float a = 1.0f / 3.0f;
    float b = 1.0f / 3.0f;
    System.out.println(a == b);
    

    on one machine it's always going to be true?

  • Custom User Avatar
  • Custom User Avatar

    Please do not open new issues unless you can confirm that your solution is correct and tests are wrong. Floating-point arithmetic is not random. You always get the same result if you follow all computation steps in the specified order. Did you see my reply to your previous issue?

  • Custom User Avatar

    Both Python and JavaScript return -20.490663944447256 for this expression. So there are no issues with tests.

    Make sure that you evaluate all operations with the same precedence from left to right and use library functions to convert decimal numbers to floating-point numbers.

    Your current solution fails the following simple test case: 1-(6-3) == -2 but you solution returns 1.

  • Custom User Avatar

    you can find out whether you are overestimating 2kyu by solving more purple kata's, go for it

  • Default User Avatar

    I'm glad you enjoyed the kata. Hopefully you solved it by your own reasoning before you found out about a "trick", and that's what's important.

  • Default User Avatar

    before trying the random tests, take a look at the sample tests, which you also fail. some remarks:

    • your code modifies array even though it is const (the compiler warns you about this), this is why the assertion messages are confusing
    • your code seems to contain undefined behavior when k > n: it makes out-of-bounds accesses on array