Ad
  • Custom User Avatar

    The best way to deal with floating point precision issues is to stay away from floating point precision issues.

    This is not always possible, but there is a class of problems (including this one) which can be solved with integers, without resorting to inexact FP operations. Notice how in this kata all inputs are integers, and all relationships between numbers are expressed in terms of integers. There's 60 seconds in a minute, there's 60 minutes in an hour, and task explicitly states that you do not need to deal with fractional tail. Find a way to express all intermediate values with integers, do not introduce any floats or doubles, and you will get rid of FP precision issues.

  • Custom User Avatar

    Could you explain or link to a page that explains how to deal with fp precision? Because I think that's my problem, I've got the correct result except for a few cases where it is off by max. 1 sec...

  • Custom User Avatar

    It's difficult to explain things via forum. You can try kata solving help gitter chat and ask for some hints, or you can share your solution here (remember about spoiler flag and code formatting) so someone could help.

  • Custom User Avatar

    hmmmm, i know right. Working with numbers can be an issue sometimes in JS. I'll be really glad if you can explain to me this easy way! will be much appreciated as i can see you've really gained a ton of knowledge from your experience

  • Custom User Avatar

    Did you pass all your test cases?

    Yes, on second attempt. But I already knew what to do and what not to do.

    [...] its just basic physics and maths algorithms.

    Yes, but no. Solution to this kata is indeed not that difficult when one knows basic physics or math. Just a simple equation. Problem is that solving an equation, even simple one, with a computer, is not the same as solving equation with a pen and paper. There are many things computers are not really good at, and one such thing is handling fractions and rational numbers. I believe you run into issues with floating point precision and rounding, don't you? There is an easy way to resolve this problem, but if you do not know it, then you will struggle.
    Things are not always as easy as one might think.

  • Custom User Avatar

    It's more like the more i re-authorand optimize my code after failing an attempt, the more it keeps failing, but this same code works in reality because its just basic physics and maths algorithms. Did you pass all your test cases?

  • Custom User Avatar

    Test cases do indeed change between runs, but it does not mean tests are broken. While random tests are not standard TDD practice, it's customary for CW kata to have a set of randomly generated test cases to prevent hardcoding and input sampling.

    If you have any specific complaints about how tests are randomized for some specific language version, then please give more details. But the fact that tests are random is actually as desired (in terms of CW kata).

  • Custom User Avatar

    Test cases are broken, constant clicking of the attempt button will give different passed and failed results. Test cases needs to be re-authored!

  • Custom User Avatar

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

  • Custom User Avatar

    wow, this's just absolutely brilliant!