Ad
  • Custom User Avatar

    Print the input yourself.

  • Custom User Avatar

    LOL - amusingly I wrote: "I have two suggestions" -- then presented 3 items.

    Reminds me of a joke:

    There are 2 hard problems in computer science: cache invalidation, naming things, and off-by-1 errors

  • Default User Avatar

    Yeah but the test did not mention which string was tested, so no debugging is possible
    (at least in python)

  • Custom User Avatar

    You've probably taken an approach that decrements the number until the new number has the same digits (i.e., next smaller) or some terminal case (e.g., 0, fewer-digits, etc.) This approach will timeout on this kata.

    To get yourself unstuck, I have two suggestions:

    1. Try some carefully chosen inputs that you know will be difficult for your algorithm. In the above case, try: 900,000,000,001 - the next smaller number with the same digits is 190,000,000,000. Why? In respect to the above algorithm, having to spin through all those decrement and digit tests needs to happen about 710 billion times. If 1 iteration required just 1 ns, the 710 billion times through the loop would require 710 seconds for just this one simple input (there will be hundreds or thousands like it in the official tests. )
    2. If your code works pretty well with hand crafted inputs, try adding code to your solution to print every 10th (or every 100th) and time those. Or some similar variation of adding timing and logging the ones that take a long time.
    3. This isn't one that I resort to often, but you can go parallel. When you're close to making the mark, sometimes this will allow your algorithm to finish in time. In general though, it's better to look for algorithmic improvements.
  • Default User Avatar

    My code finds the answer in:
    177 ns ± 2.46 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each),
    but time outs on the server.
    next_smaller(11911)
    ->11191

  • Default User Avatar

    Hello World.

    How do I see hidden input values?
    My code executes in 200ns localy on a large number like (123456789123456789123456789123456789123456789), but it time outs on the server and idk why.

    %timeit next_smaller(9525144338352127488)
    9525144338352124887
    184 ns ± 0.33 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

    Execution Timed Out (12000 ms) O_O

    Thx.

  • Default User Avatar

    My solution looks ugly but it's 2.5 times faster than the one at the top of Best Practices :)

  • Custom User Avatar

    Not an issue.

  • Custom User Avatar

    Your solution returned a wrong result.

  • Custom User Avatar

    Because True is not a number.

  • Default User Avatar

    Why tests say "True should equal False"?

  • Custom User Avatar

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

  • Custom User Avatar
  • Custom User Avatar

    Try reading the examples and problem description one more time

  • Default User Avatar

    Welp, for me tests say 7 should equal 3. :| Python

  • Loading more items...