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.
OP solved it, closing
also same. standard tests all going trough but with random i always have ERROR as a result
If there wasn't a pattern, you would have to iterate all of them like you started doing in the code sample.
I could tell you what the pattern is, but discovering it and translating it into code is where the fun in this kata is at.
You should get started in looking for a pattern by ouputting the first few numbers in binary (for example, 0..15), leftpad them with with 0's to make 4 bits -- then see if you can recognize the pattern.
Happy hunting.
I am sorry about your experience with this kata. My intent in this kata was to require some algorithm design thought beyond the "simple decrement and check-the-digits" kinds of implementations that I intended to weed out through them taking too long to run. I looked at the top-rated javascript solution and realized that they got away with precisely this kind of inefficient solution I wanted to prevent. So it's clear that my big-random-number acceptance tests must be flawed. With randomized data, some kata can be completed by simply resubmitting and getting lucky with the new randomized test cases.
Regardless, I left a comment on their solution and will probably write a new performance version of this kata that ensures that such solutions will fail. I have other ideas about how to thwart such solutions, however, had I generated a number like: 900000001 (900 million + 1). The next smaller number with the same digits is: 190000000 (i.e., 190 million) -- a decrement-and-check-digits approach will have to spin through nearly 710 million numbers that do not have the same digits to find in order to find this one.
The other sites you mention must include a similar 'your algorithm took too long to run' timeout (that may be longer than code wars' 12 seconds); otherwise, they are vulnerable to a runaway infinite loop taking down their services.
Since your solution timed-out, you could post it here if you like, and I will be happy to review it. You can mark it as a spoiler, if you like -- to keep from giving hints away to others that haven't solved it yet.
Thanks,
I can't know what you're doing wrong without seeing the code
https://en.wikipedia.org/wiki/A_picture_is_worth_a_thousand_words
Or you can look at this the other way around: they spoonfeed you at every moment...?
I agree there are a lot of poorly described problems on cw, but that's not the case for this one, even if it's effectively rather minimalist. The idea here isn't to provide the algorithm to you, it's up to you to identify it. If you carefully study the example of the description, you should see that it can answer to all the questions about what you should do in what case.
Hi,
Not an issue, a question (the kata is working as intended, that's your code that has a problem).
You need to change your approach to have a more efficient algorithm (I cannot say more without giving up the solution).
in java (always tell about the language!), input goes up to 1000000.
Cheers