Cody

# Problem 68. Kaprekar Steps

Solution 1478695

Submitted on 4 Apr 2018 by Yanni Wang
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
x = 3276; y_correct = 5; assert(isequal(KaprekarSteps(x),y_correct))

digit_index = 1000 100 10 1 y = 0 b = 7 6 3 2 b = 7 6 3 2 b_right = 2 3 6 7 x2 = 2367 x = 5265 y = 1 b = 6 5 5 2 b = 6 5 5 2 b_right = 2 5 5 6 x2 = 2556 x = 3996 y = 2 b = 9 9 6 3 b = 9 9 6 3 b_right = 3 6 9 9 x2 = 3699 x = 6264 y = 3 b = 6 6 4 2 b = 6 6 4 2 b_right = 2 4 6 6 x2 = 2466 x = 4176 y = 4 b = 7 6 4 1 b = 7 6 4 1 b_right = 1 4 6 7 x2 = 1467 x = 6174 y = 5

2   Pass
x = 3; y_correct = 6; assert(isequal(KaprekarSteps(x),y_correct))

digit_index = 1000 100 10 1 y = 0 b = 3 b = 3 0 0 0 b_right = 0 0 0 3 x2 = 3 x = 2997 y = 1 b = 9 9 7 2 b = 9 9 7 2 b_right = 2 7 9 9 x2 = 2799 x = 7173 y = 2 b = 7 7 3 1 b = 7 7 3 1 b_right = 1 3 7 7 x2 = 1377 x = 6354 y = 3 b = 6 5 4 3 b = 6 5 4 3 b_right = 3 4 5 6 x2 = 3456 x = 3087 y = 4 b = 8 7 3 0 b = 8 7 3 0 b_right = 0 3 7 8 x2 = 378 x = 8352 y = 5 b = 8 5 3 2 b = 8 5 3 2 b_right = 2 3 5 8 x2 = 2358 x = 6174 y = 6

3   Pass
x = 691; y_correct = 7; assert(isequal(KaprekarSteps(x),y_correct))

digit_index = 1000 100 10 1 y = 0 b = 9 6 1 b = 9 6 1 0 b_right = 0 1 6 9 x2 = 169 x = 9441 y = 1 b = 9 4 4 1 b = 9 4 4 1 b_right = 1 4 4 9 x2 = 1449 x = 7992 y = 2 b = 9 9 7 2 b = 9 9 7 2 b_right = 2 7 9 9 x2 = 2799 x = 7173 y = 3 b = 7 7 3 1 b = 7 7 3 1 b_right = 1 3 7 7 x2 = 1377 x = 6354 y = 4 b = 6 5 4 3 b = 6 5 4 3 b_right = 3 4 5 6 x2 = 3456 x = 3087 y = 5 b = 8 7 3 0 b = 8 7 3 0 b_right = 0 3 7 8 x2 = 378 x = 8352 y = 6 b = 8 5 3 2 b = 8 5 3 2 b_right = 2 3 5 8 x2 = 2358 x = 6174 y = 7

4   Pass
x = 3333; y_correct = Inf; assert(isequal(KaprekarSteps(x),y_correct))

digit_index = 1000 100 10 1 y = 0 b = 3 3 3 3 b = 3 3 3 3 y = Inf

5   Pass
x = 1; y_correct = 5; assert(isequal(KaprekarSteps(x),y_correct))

digit_index = 1000 100 10 1 y = 0 b = 1 b = 1 0 0 0 b_right = 0 0 0 1 x2 = 1 x = 999 y = 1 b = 9 9 9 b = 9 9 9 0 b_right = 0 9 9 9 x2 = 999 x = 8991 y = 2 b = 9 9 8 1 b = 9 9 8 1 b_right = 1 8 9 9 x2 = 1899 x = 8082 y = 3 b = 8 8 2 0 b = 8 8 2 0 b_right = 0 2 8 8 x2 = 288 x = 8532 y = 4 b = 8 5 3 2 b = 8 5 3 2 b_right = 2 3 5 8 x2 = 2358 x = 6174 y = 5

6   Pass
x = 6174; y_correct = 0; assert(isequal(KaprekarSteps(x),y_correct))

digit_index = 1000 100 10 1 y = 0

7   Pass
x = 1234; y_correct = 3; assert(isequal(KaprekarSteps(x),y_correct))

digit_index = 1000 100 10 1 y = 0 b = 4 3 2 1 b = 4 3 2 1 b_right = 1 2 3 4 x2 = 1234 x = 3087 y = 1 b = 8 7 3 0 b = 8 7 3 0 b_right = 0 3 7 8 x2 = 378 x = 8352 y = 2 b = 8 5 3 2 b = 8 5 3 2 b_right = 2 3 5 8 x2 = 2358 x = 6174 y = 3

8   Pass
x = 3141; y_correct = 5; assert(isequal(KaprekarSteps(x),y_correct))

digit_index = 1000 100 10 1 y = 0 b = 4 3 1 1 b = 4 3 1 1 b_right = 1 1 3 4 x2 = 1134 x = 3177 y = 1 b = 7 7 3 1 b = 7 7 3 1 b_right = 1 3 7 7 x2 = 1377 x = 6354 y = 2 b = 6 5 4 3 b = 6 5 4 3 b_right = 3 4 5 6 x2 = 3456 x = 3087 y = 3 b = 8 7 3 0 b = 8 7 3 0 b_right = 0 3 7 8 x2 = 378 x = 8352 y = 4 b = 8 5 3 2 b = 8 5 3 2 b_right = 2 3 5 8 x2 = 2358 x = 6174 y = 5

9   Pass
x = 8080; y_correct = 6; assert(isequal(KaprekarSteps(x),y_correct))

digit_index = 1000 100 10 1 y = 0 b = 8 8 0 0 b = 8 8 0 0 b_right = 0 0 8 8 x2 = 88 x = 8712 y = 1 b = 8 7 2 1 b = 8 7 2 1 b_right = 1 2 7 8 x2 = 1278 x = 7443 y = 2 b = 7 4 4 3 b = 7 4 4 3 b_right = 3 4 4 7 x2 = 3447 x = 3996 y = 3 b = 9 9 6 3 b = 9 9 6 3 b_right = 3 6 9 9 x2 = 3699 x = 6264 y = 4 b = 6 6 4 2 b = 6 6 4 2 b_right = 2 4 6 6 x2 = 2466 x = 4176 y = 5 b = 7 6 4 1 b = 7 6 4 1 b_right = 1 4 6 7 x2 = 1467 x = 6174 y = 6