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.
hyper brainy
mine respect
This comment is hidden because it contains spoiler information about the solution
It is unclear what the failure message means when a test failed:
What it's probably trying to say is using
0
and1
at indexi
to mark whetheri+1
can be represented by the ruler, but then again, this is not informative test feedback.There are no sample tests or random tests.
my brain isn't braining
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 counting9
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 inputn
goes to10**19
- try your function with this value on your PC tests if you want to see how fast it is.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
Hi @eiphorie - in random tests, the value of
n
goes up to10**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
This comment is hidden because it contains spoiler information about the solution
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 :(
molto bene! :chef's_kiss:
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.
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.
@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!!
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 produces6848946955413282816
while the correct answer is6848946955413282633
.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
inprint(n,i,r)
in your code with the above large input. What is happening tor
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...