Ad
  • Custom User Avatar

    OP solved it, closing

  • Custom User Avatar
  • Default User Avatar

    also same. standard tests all going trough but with random i always have ERROR as a result

  • Custom User Avatar

    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.

  • Custom User Avatar

    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,

  • Custom User Avatar

    I can't know what you're doing wrong without seeing the code

  • Custom User Avatar
  • Custom User Avatar

    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.

  • Custom User Avatar

    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