Ad
  • Default User Avatar

    the if statement works only if condition is true, so if b was a true it will run and return a True and else otherwise,

    and if you're talking about the way he write the code this the shorthand if statement in return statement

  • Custom User Avatar

    This code returns string either way I guess :D

  • Custom User Avatar

    could someone explain the concept behind this

  • Custom User Avatar

    JS update fork

    • Uses chai for assertion
    • Assertion messages now shows the input number
  • 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:

  • Loading more items...