Cody

# Problem 68. Kaprekar Steps

Solution 1530951

Submitted on 16 May 2018 by William Moraga
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))

first = '2367' second = '7632' step = 1 first = '2556' second = '6552' step = 2 first = '3699' second = '9963' step = 3 first = '2466' second = '6642' step = 4 first = '1467' second = '7641' step = 5

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

first = '3' second = '3' second = '3000' step = 1 first = '2799' second = '9972' step = 2 first = '1377' second = '7731' step = 3 first = '3456' second = '6543' step = 4 first = '0378' second = '8730' step = 5 first = '2358' second = '8532' step = 6

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

first = '169' second = '961' second = '9610' step = 1 first = '1449' second = '9441' step = 2 first = '2799' second = '9972' step = 3 first = '1377' second = '7731' step = 4 first = '3456' second = '6543' step = 5 first = '0378' second = '8730' step = 6 first = '2358' second = '8532' step = 7

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

first = '3333' second = '3333' step = 1 y = Inf

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

first = '1' second = '1' second = '1000' step = 1 first = '999' second = '999' second = '9990' step = 2 first = '1899' second = '9981' step = 3 first = '0288' second = '8820' step = 4 first = '2358' second = '8532' step = 5

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

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

first = '1234' second = '4321' step = 1 first = '0378' second = '8730' step = 2 first = '2358' second = '8532' step = 3

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

first = '1134' second = '4311' step = 1 first = '1377' second = '7731' step = 2 first = '3456' second = '6543' step = 3 first = '0378' second = '8730' step = 4 first = '2358' second = '8532' step = 5

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

first = '0088' second = '8800' step = 1 first = '1278' second = '8721' step = 2 first = '3447' second = '7443' step = 3 first = '3699' second = '9963' step = 4 first = '2466' second = '6642' step = 5 first = '1467' second = '7641' step = 6