Ad
  • Default User Avatar

    My directions already stated, "Your job is to return the best starting mark in meters, rounded to two decimal places." I don't know of any katas on Codewars that expect you to round earlier in the process of solving the problem. It should be rather obvious that any imprecision resulting from such early rounding could be compounded in the final result. So unless you find an explicit exception to this rule, you should assume that the rounding always occurs at the end.

    I don't set the difficulty level of my own kata. That is determined by other people, who apparently didn't find this one sufficiently challenging to rank it higher.

    Please don't enter "issues" on kata when the problem lies in your own lack of knowledge, ineffective solution, or failure to read the instructions. It is not appreciated here, as you will note in many of the forums. In this situation, marking your comment as a "question" would have been the appropriate alternative.

    In any event, I am glad that you learned something along the way.

  • Custom User Avatar

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

  • Custom User Avatar

    C# doubles represent IEEE 754 64 bit floating point values (see .NET documentation).

    Some values are not representable by double, like 0.33 (which is stored as 0.33000000000000002) or 9.45 (which is stored as 9.4499999999999993).

    Math.Round(x, 2) multiplies x by 100, and then determines whether the remaining fractional portion of the value is greater than or equal to 0.5 (see Math.Round documentation).

    If you calculate with values that differ slightly from the "real" values those difference might grow. E.g. 1.235 * 4.565 == 5.637775, rounded to two decimal digits is 5.64. But if you round first you get 1.24 * 4.57 == 5.6668, rounded to two decimal digits is 5.67. The difference between the two multiplicants and their rounded counterparts is smaller than 0.01 but the products differ by 0.03.

    Generally speaking, use the highest precision available and only round at the end (if you have to).

  • Custom User Avatar

    General advice:

    1. Get the parameters of the failed test. AFAIK every programming language here at CodeWars has some way to print something.
    2. Get your result.
    3. Re-read the kata's description. There are a lot of issues where the user missed something in the description.
    4. Check your result manually (if possible). There are quite a few issues where the user's result was just wrong.
    5. Check that kata's discourse section if this issue has already been reported.
    6. Add a comment.
      • State your programming language and version as shown at the top of the page.
      • State the parameters of the failed test, your result and the expected result (if available).
      • Add your solution code surrounded by a line with just three backticks (```) and mark the comment as "having spoiler content".
      • Label the comment as "Issue".
    7. Give the author a few days to respond.
  • Default User Avatar

    What language are you using to solve it? Some of the problems reported previously have been specific to certain languages, so I'd like to determine whether that is also the case here.