Ad
  • Custom User Avatar
  • Custom User Avatar

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

  • Custom User Avatar

    It is unclear what the failure message means when a test failed:

    Expected: '111111111', instead got: '111111011'
    

    What it's probably trying to say is using 0 and 1 at index i to mark whether i+1 can be represented by the ruler, but then again, this is not informative test feedback.

  • Custom User Avatar

    There are no sample tests or random tests.

  • Default User Avatar
  • Default User Avatar

    I don't use JavaScript so I can't see your current solution, but if you are going through all numbers up to n and counting 9 inside each one, it will be too slow (even with just this "simple loop" rather than an "infinite loop").

    Maybe the 50ms timing is for very small tests you have tried? Like with n = 100 or something? In the full kata tests the input n goes to 10**19 - try your function with this value on your PC tests if you want to see how fast it is.

  • Custom User Avatar

    My function finish it in 50ms but on codewars i can't run tests , it's saying that the function times out. Can't because the code is fast with no infinite loops

  • Default User Avatar

    Hi @eiphorie - in random tests, the value of n goes up to 10**19 or so meaning that actually creating the string is impossible, let alone counting inside it.

    You have to find a smarter way to get the answer - for this, you can use your solution for smaller values of n to maybe try to find some patterns or help you debug.

    This is actually more of a mathematics/logic type kata, so if you don't get the answer straight away then practicing on other katas will definitely improve your ability to "see" the correct approach and techniques. Hope that helps a bit

  • Custom User Avatar

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

  • Default User Avatar

    I'm having the same issue. It was easy to come up with a simple algorithm, but it takes too much time.
    It seems that the objective of the kata is indeed to create an optimized algorithm, and that's really hard.
    I feel this kata should be at least 2-3kyu, not 5 :(

  • Custom User Avatar

    molto bene! :chef's_kiss:

  • Default User Avatar

    User solved it (I copied View Solution code and started debugging, but passed Attempt on first try) but didn't bother to close Question afterwards -.-

    No problems with Python tests therefore & closing Question.

  • Default User Avatar

    Reading through discourse 2023/01/07: I noticed this Issue and will close it now as I have fixed this behaviour in the Python tests.

    A user had the same problem today so I made a simple edit to the tests - the Python error message now is correct:

    "Testing count_nines({RANDOM N}) - Correct answer is: {CORRECT ANSWER}, but you returned: {USER SOLUTION}"

    Previously the message flipped the CORRECT and USER, which was leading to a lot of confusion it seems.

  • Default User Avatar

    @Dr. Whatever - just to confirm, I have now edited the tests; the Error Message for the random Attempt Cases should now be clear.

    To repeat - you will need to Reset the kata trainer for this to take effect, but please save your code somewhere as it will be deleted when you press reset!!

  • Default User Avatar

    Hi @Dr Whatever - thanks for raising this Issue; there is in fact a problem with the current Attempt Tests:

    when the error message displays "count_nines({}): expected {}, got {}"

    it is currently (mistakenly) showing your answer as the Expected and the Correct Answer as ", got {}". So confusingly it seems as if your answer is always the correct one, but in fact the 2 have been swapped.

    I am going to edit tests now to correct this - you will need to Reset the kata if you want to attempt with the updates(save your work first to a textfile or local file!!)

    Note however that your answer is still incorrect though: for input 3855981362897834653 your code produces 6848946955413282816 while the correct answer is 6848946955413282633.

    To see what's going wrong with your code, you should paste it into an IDE and pay particular attention to the value of r in print(n,i,r) in your code with the above large input. What is happening to r as you reach very large values? Do you notice something strange with the very large numbers that appear on your screen? That's where you are going wrong.

  • Loading more items...