6 kyu

Increment with iterations

98 of 192Sicely
Description
Loading description...
Algorithms
  • Please sign in or sign up to leave a comment.
  • dfhwze Avatar

    I don't understand this kata. What are we supposed to do in terms of steps when the number gets bigger?

    given number:9999, iterations:9, step: 9
    Log
    [ 9, 9, 9, 9 ]
    
    pos: 1
    [ 1, 0, 0, 9, 9 ]
    
    pos: 0
    [ 2, 0, 0, 9, 9 ]
    
    pos: 4
    [ 2, 0, 1, 0, 0 ]
    
    pos: 3
    [ 2, 0, 1, 1, 0 ]
    
    pos: 2
    [ 2, 0, 2, 1, 0 ]
    
    pos: 1
    [ 2, 1, 2, 1, 0 ]
    
    pos: 0
    [ 3, 1, 2, 1, 0 ]
    
    pos: 4
    [ 3, 1, 2, 1, 1 ]
    
    pos: 3
    [ 3, 1, 2, 2, 1 ]
    expected 31221 to deeply equal 32211
    
  • feverila Avatar

    Ok so maybe this isn't a worthy question but. How do i iterate through the number, because when i increment the index it gets out of range. So like number[i+spacer] is out of range.

  • JoeWolfe12 Avatar

    I got caught up on the position moving to the right if the number of digits increases for ages! Good puzzle though - definitely one of the better 6 kata ones.

  • erikvernooij Avatar

    It always passes?

  • JohanWiltink Avatar
    • Sicely Avatar

      Can you explain, in your translation run not only 3 tests,right? He has a loop with many tests, but if one test of loop failed, all will too be failed? Thx, for translation!

      Suggestion marked resolved by Sicely 5 years ago
    • JohanWiltink Avatar

      If any individual test fails, the solution fails. If all tests pass, the solution passes.

      This is shown as 3 tests, but 114 are run in total ( 3 example tests, 11 fixed tests, 100 random tests ).

  • Blind4Basics Avatar

    Hi,

    • missing an edge case like this:

      assert.deepEqual(increment(9,9000,100), 1854892466545716 );   // Note: I'm just hoping my code is correct there x)
      
    • still some typos in the first sentence: aN algorithm, increaseS number in THE way

    • Sicely Avatar

      Thx for typo. Fix that. But i dont undestend what you mean about your edge case. I wrote randoms tests where number < 10000, step and iteration < 100. So big number like in your example not a real in my problem. Please explain more detail. Thx for help to upgrade my problem.

    • Blind4Basics Avatar

      it's a "just in case" test. Not sure it would invalidate anything, but there aren't that many tests with the step bigger than the number, and the number growing in size (number of digits) at the same time. Here, it's growing a lot, with the step being a lot longer that the number itself, but this one varying. Basically, it's supposed to forbid bad ways to handle a step longer than the number it'self. Hopefully... x)

    • Sicely Avatar

      I am realy newbie in JS and Codewars, so me need just add this case assert.deepEqual(increment(9,9000,100), 1854892466545716 ); to basic test? Before i have a problem with max save int, so i rewrite cata with limitations(10000 for num, and 100 for other), and check all solution in this interval(all be fine). So, if you clealy know your test is needed in this cata, you can contribute him. Becouse i havent so exp to make right decision. Thanks for your help. Sorry if i spend your time.

      Suggestion marked resolved by Sicely 5 years ago
    • Blind4Basics Avatar

      just add it to the "Common tests", yes. the expected value is still below the MAX_SAFE_INTEGER, so it won't cause troubles (I just checked against other solution using different approaches and it passed).

    • Sicely Avatar

      Ready, thx for advice :)

  • JohanWiltink Avatar

    Are you using the user solution for the random tests? That'll always pass! :D

    You should be using a reference ( known good ) solution to calculate the expected answer.

  • JohanWiltink Avatar

    Can we have Node v10.x? I want native BigInts.

    Also, if we have to return an exact number with full precision, native Numbers are not ideal. Consider Strings or BigInts.

    • Sicely Avatar

      Resolved now. Delete test with number greater then max safe int, and add some random test. Thx for help :)

      Suggestion marked resolved by Sicely 5 years ago
    • JohanWiltink Avatar

      There was something weird with the language version, so I republished with default version set to Node 10. That seemed to work. Then I fixed the description for a couple of spelling errors. Hope you don't mind.

  • JohanWiltink Avatar

    When leading nines overflow into a longer number, does the current position get shifted to the right?

    This is not clear from the description.

  • Unnamed Avatar

    Random tests should be added. More tests with big numbers should be added.