Cody

# Problem 68. Kaprekar Steps

Solution 719230

Submitted on 21 Aug 2015 by Ian Riley
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))

y = 0 xstr = 3276 asc = 2367 des = 7632 x = 5265 y = 1 xstr = 5265 asc = 2556 des = 6552 x = 3996 y = 2 xstr = 3996 asc = 3699 des = 9963 x = 6264 y = 3 xstr = 6264 asc = 2466 des = 6642 x = 4176 y = 4 xstr = 4176 asc = 1467 des = 7641 x = 6174 y = 5

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

y = 0 xstr = 3 xstr = 03 xstr = 003 xstr = 0003 asc = 3 des = 3000 x = 2997 y = 1 xstr = 2997 asc = 2799 des = 9972 x = 7173 y = 2 xstr = 7173 asc = 1377 des = 7731 x = 6354 y = 3 xstr = 6354 asc = 3456 des = 6543 x = 3087 y = 4 xstr = 3087 asc = 378 des = 8730 x = 8352 y = 5 xstr = 8352 asc = 2358 des = 8532 x = 6174 y = 6

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

y = 0 xstr = 691 xstr = 0691 asc = 169 des = 9610 x = 9441 y = 1 xstr = 9441 asc = 1449 des = 9441 x = 7992 y = 2 xstr = 7992 asc = 2799 des = 9972 x = 7173 y = 3 xstr = 7173 asc = 1377 des = 7731 x = 6354 y = 4 xstr = 6354 asc = 3456 des = 6543 x = 3087 y = 5 xstr = 3087 asc = 378 des = 8730 x = 8352 y = 6 xstr = 8352 asc = 2358 des = 8532 x = 6174 y = 7

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

y = 0 xstr = 3333 asc = 3333 des = 3333 x = 0 y = 1 y = Inf

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

y = 0 xstr = 1 xstr = 01 xstr = 001 xstr = 0001 asc = 1 des = 1000 x = 999 y = 1 xstr = 999 xstr = 0999 asc = 999 des = 9990 x = 8991 y = 2 xstr = 8991 asc = 1899 des = 9981 x = 8082 y = 3 xstr = 8082 asc = 288 des = 8820 x = 8532 y = 4 xstr = 8532 asc = 2358 des = 8532 x = 6174 y = 5

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

y = 0

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

y = 0 xstr = 1234 asc = 1234 des = 4321 x = 3087 y = 1 xstr = 3087 asc = 378 des = 8730 x = 8352 y = 2 xstr = 8352 asc = 2358 des = 8532 x = 6174 y = 3

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

y = 0 xstr = 3141 asc = 1134 des = 4311 x = 3177 y = 1 xstr = 3177 asc = 1377 des = 7731 x = 6354 y = 2 xstr = 6354 asc = 3456 des = 6543 x = 3087 y = 3 xstr = 3087 asc = 378 des = 8730 x = 8352 y = 4 xstr = 8352 asc = 2358 des = 8532 x = 6174 y = 5

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

y = 0 xstr = 8080 asc = 88 des = 8800 x = 8712 y = 1 xstr = 8712 asc = 1278 des = 8721 x = 7443 y = 2 xstr = 7443 asc = 3447 des = 7443 x = 3996 y = 3 xstr = 3996 asc = 3699 des = 9963 x = 6264 y = 4 xstr = 6264 asc = 2466 des = 6642 x = 4176 y = 5 xstr = 4176 asc = 1467 des = 7641 x = 6174 y = 6