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.
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.
This comment is hidden because it contains spoiler information about the solution
Immediately came to the discussion after understanding that it's a good kata. I wonder how long i will take.
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:
The expected result is
7.263867809057526
but your solution returns-915.278670000000034
.A simplified version of this test case:
Expected:
8
, your solution:799.087999999999965
.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).Sorry for a bit dumb question.
Does this mean that if I do something like
on one machine it's always going to be true?
Chill :c
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?
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 returns1
.you can find out whether you are overestimating 2kyu by solving more purple kata's, go for it
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.
before trying the random tests, take a look at the sample tests, which you also fail. some remarks:
array
even though it isconst
(the compiler warns you about this), this is why the assertion messages are confusingk > n
: it makes out-of-bounds accesses onarray