Ad
  • Custom User Avatar

    They're in a numbered list, so minimizing i should take precedence over minimizing j.

  • Default User Avatar

    Chrono79, as you say i must be as small as possible. But it also says the same about j with no statement about which should take precedence. In the case of 0, 1 it could also be done as 1, 0 with the same effect (and this would be the simpler way too). I might have misunderstood but it seems for the 0, 1 case to make sense another explicit rule would need to be in the text.

  • Custom User Avatar

    No problem, but starting from 269045 and using i = 0 and j = 3 would be 690245, don't forget the 0 will be still there ;)

  • Custom User Avatar

    The input is 269045 right?
    The smallest number you get following the kata instructions is 26945
    i is the index of the digit you move, you don't get 26945 moving the 2 (index 0), you get that number moving the 0 (index 3)

    1. the index i of the digit d you took, i as small as possible
    2. the index j (as small as possible) where you insert this digit d to have the smallest number.

    Maybe you'll see it better if you write it as 026945 that as a number is 26945. You don't swap two digits either, you take a single digit and move it.

  • Custom User Avatar

    No, they're not, read what I wrote again, first case you move the 2 and second case you move the 0, why? Because you want i as small as possible, so [29917, 1, 0] is not a solution and [29917, 0, 1] is. In the second case you have to move the 0, not the 2 to get the smallest possible number.

  • Custom User Avatar

    Next time use Question, not issue if you don't understand something.
    Finding the smallest digit and moving it is not the first step in both cases.
    In the first case, you take the 2 (index 0) and insert it back at index 1.
    In the second case, you take the 0 (index 3) and insert it back at index 0.

  • Custom User Avatar

    Exit Code: 139

    Segfault.