Cody

# Problem 68. Kaprekar Steps

Solution 1630158

Submitted on 19 Sep 2018 by Deepthi Palagati
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))

n = 3276 len = 4 ascen = '2367' descen = '7632' n = 5265 len = 4 ascen = '2556' descen = '6552' n = 3996 len = 4 ascen = '3699' descen = '9963' n = 6264 len = 4 ascen = '2466' descen = '6642' n = 4176 len = 4 ascen = '1467' descen = '7641' n = 6174

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

n = 3 len = 1 str = '0003' ascen = '0003' descen = '3000' n = 2997 len = 4 ascen = '2799' descen = '9972' n = 7173 len = 4 ascen = '1377' descen = '7731' n = 6354 len = 4 ascen = '3456' descen = '6543' n = 3087 len = 4 ascen = '0378' descen = '8730' n = 8352 len = 4 ascen = '2358' descen = '8532' n = 6174

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

n = 691 len = 3 str = '0691' ascen = '0169' descen = '9610' n = 9441 len = 4 ascen = '1449' descen = '9441' n = 7992 len = 4 ascen = '2799' descen = '9972' n = 7173 len = 4 ascen = '1377' descen = '7731' n = 6354 len = 4 ascen = '3456' descen = '6543' n = 3087 len = 4 ascen = '0378' descen = '8730' n = 8352 len = 4 ascen = '2358' descen = '8532' n = 6174

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

n = 3333 len = 4 ascen = '3333' descen = '3333' num = Inf

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

n = 1 len = 1 str = '0001' ascen = '0001' descen = '1000' n = 999 len = 3 str = '0999' ascen = '0999' descen = '9990' n = 8991 len = 4 ascen = '1899' descen = '9981' n = 8082 len = 4 ascen = '0288' descen = '8820' n = 8532 len = 4 ascen = '2358' descen = '8532' n = 6174

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

n = 6174

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

n = 1234 len = 4 ascen = '1234' descen = '4321' n = 3087 len = 4 ascen = '0378' descen = '8730' n = 8352 len = 4 ascen = '2358' descen = '8532' n = 6174

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

n = 3141 len = 4 ascen = '1134' descen = '4311' n = 3177 len = 4 ascen = '1377' descen = '7731' n = 6354 len = 4 ascen = '3456' descen = '6543' n = 3087 len = 4 ascen = '0378' descen = '8730' n = 8352 len = 4 ascen = '2358' descen = '8532' n = 6174

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

n = 8080 len = 4 ascen = '0088' descen = '8800' n = 8712 len = 4 ascen = '1278' descen = '8721' n = 7443 len = 4 ascen = '3447' descen = '7443' n = 3996 len = 4 ascen = '3699' descen = '9963' n = 6264 len = 4 ascen = '2466' descen = '6642' n = 4176 len = 4 ascen = '1467' descen = '7641' n = 6174

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!