Cody

Problem 68. Kaprekar Steps

Solution 2013129

Submitted on 11 Nov 2019 by Le Quynh Trang Ngo
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))

des = 7632 asc = 2367 result = 5265 x = 5265 des = 6552 asc = 2556 result = 3996 x = 3996 des = 9963 asc = 3699 result = 6264 x = 6264 des = 6642 asc = 2466 result = 4176 x = 4176 des = 7641 asc = 1467 result = 6174 x = 6174 y = 5

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

des = 3000 asc = 3 result = 2997 x = 2997 des = 9972 asc = 2799 result = 7173 x = 7173 des = 7731 asc = 1377 result = 6354 x = 6354 des = 6543 asc = 3456 result = 3087 x = 3087 des = 8730 asc = 378 result = 8352 x = 8352 des = 8532 asc = 2358 result = 6174 x = 6174 y = 6

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

des = 9610 asc = 169 result = 9441 x = 9441 des = 9441 asc = 1449 result = 7992 x = 7992 des = 9972 asc = 2799 result = 7173 x = 7173 des = 7731 asc = 1377 result = 6354 x = 6354 des = 6543 asc = 3456 result = 3087 x = 3087 des = 8730 asc = 378 result = 8352 x = 8352 des = 8532 asc = 2358 result = 6174 x = 6174 y = 7

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

des = 3333 asc = 3333 result = 0 y = Inf

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

des = 1000 asc = 1 result = 999 x = 999 des = 9990 asc = 999 result = 8991 x = 8991 des = 9981 asc = 1899 result = 8082 x = 8082 des = 8820 asc = 288 result = 8532 x = 8532 des = 8532 asc = 2358 result = 6174 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))

des = 4321 asc = 1234 result = 3087 x = 3087 des = 8730 asc = 378 result = 8352 x = 8352 des = 8532 asc = 2358 result = 6174 x = 6174 y = 3

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

des = 4311 asc = 1134 result = 3177 x = 3177 des = 7731 asc = 1377 result = 6354 x = 6354 des = 6543 asc = 3456 result = 3087 x = 3087 des = 8730 asc = 378 result = 8352 x = 8352 des = 8532 asc = 2358 result = 6174 x = 6174 y = 5

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

des = 8800 asc = 88 result = 8712 x = 8712 des = 8721 asc = 1278 result = 7443 x = 7443 des = 7443 asc = 3447 result = 3996 x = 3996 des = 9963 asc = 3699 result = 6264 x = 6264 des = 6642 asc = 2466 result = 4176 x = 4176 des = 7641 asc = 1467 result = 6174 x = 6174 y = 6