Cody

# Problem 68. Kaprekar Steps

Solution 2112652

Submitted on 31 Jan 2020 by Eric Grant
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))

res = '3276' n1 = 2367 n2 = 7632 res = 5265 res = '5265' res = '5265' n1 = 2556 n2 = 6552 res = 3996 res = '3996' res = '3996' n1 = 3699 n2 = 9963 res = 6264 res = '6264' res = '6264' n1 = 2466 n2 = 6642 res = 4176 res = '4176' res = '4176' n1 = 1467 n2 = 7641 res = 6174 res = '6174' res = '6174' y = 5

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

res = '0003' n1 = 3 n2 = 3000 res = 2997 res = '2997' res = '2997' n1 = 2799 n2 = 9972 res = 7173 res = '7173' res = '7173' n1 = 1377 n2 = 7731 res = 6354 res = '6354' res = '6354' n1 = 3456 n2 = 6543 res = 3087 res = '3087' res = '3087' n1 = 378 n2 = 8730 res = 8352 res = '8352' res = '8352' n1 = 2358 n2 = 8532 res = 6174 res = '6174' res = '6174' y = 6

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

res = '0691' n1 = 169 n2 = 9610 res = 9441 res = '9441' res = '9441' n1 = 1449 n2 = 9441 res = 7992 res = '7992' res = '7992' n1 = 2799 n2 = 9972 res = 7173 res = '7173' res = '7173' n1 = 1377 n2 = 7731 res = 6354 res = '6354' res = '6354' n1 = 3456 n2 = 6543 res = 3087 res = '3087' res = '3087' n1 = 378 n2 = 8730 res = 8352 res = '8352' res = '8352' n1 = 2358 n2 = 8532 res = 6174 res = '6174' res = '6174' y = 7

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

res = '3333' n1 = 3333 n2 = 3333 res = 0 i = Inf y = Inf

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

res = '0001' n1 = 1 n2 = 1000 res = 999 res = '999' res = '0999' n1 = 999 n2 = 9990 res = 8991 res = '8991' res = '8991' n1 = 1899 n2 = 9981 res = 8082 res = '8082' res = '8082' n1 = 288 n2 = 8820 res = 8532 res = '8532' res = '8532' n1 = 2358 n2 = 8532 res = 6174 res = '6174' res = '6174' y = 5

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

res = '6174' y = 0

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

res = '1234' n1 = 1234 n2 = 4321 res = 3087 res = '3087' res = '3087' n1 = 378 n2 = 8730 res = 8352 res = '8352' res = '8352' n1 = 2358 n2 = 8532 res = 6174 res = '6174' res = '6174' y = 3

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

res = '3141' n1 = 1134 n2 = 4311 res = 3177 res = '3177' res = '3177' n1 = 1377 n2 = 7731 res = 6354 res = '6354' res = '6354' n1 = 3456 n2 = 6543 res = 3087 res = '3087' res = '3087' n1 = 378 n2 = 8730 res = 8352 res = '8352' res = '8352' n1 = 2358 n2 = 8532 res = 6174 res = '6174' res = '6174' y = 5

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

res = '8080' n1 = 88 n2 = 8800 res = 8712 res = '8712' res = '8712' n1 = 1278 n2 = 8721 res = 7443 res = '7443' res = '7443' n1 = 3447 n2 = 7443 res = 3996 res = '3996' res = '3996' n1 = 3699 n2 = 9963 res = 6264 res = '6264' res = '6264' n1 = 2466 n2 = 6642 res = 4176 res = '4176' res = '4176' n1 = 1467 n2 = 7641 res = 6174 res = '6174' res = '6174' y = 6