Cody

Problem 68. Kaprekar Steps

Solution 2511422

Submitted on 10 Jun 2020 by Drake Madison
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 nstr = '3276' nstr_asc = '2367' nstr_desc = '7632' x = 5265 y = 1 nstr = '5265' nstr_asc = '2556' nstr_desc = '6552' x = 3996 y = 2 nstr = '3996' nstr_asc = '3699' nstr_desc = '9963' x = 6264 y = 3 nstr = '6264' nstr_asc = '2466' nstr_desc = '6642' x = 4176 y = 4 nstr = '4176' nstr_asc = '1467' nstr_desc = '7641' x = 6174 y = 5

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

y = 0 nstr = '0003' nstr_asc = '0003' nstr_desc = '3000' x = 2997 y = 1 nstr = '2997' nstr_asc = '2799' nstr_desc = '9972' x = 7173 y = 2 nstr = '7173' nstr_asc = '1377' nstr_desc = '7731' x = 6354 y = 3 nstr = '6354' nstr_asc = '3456' nstr_desc = '6543' x = 3087 y = 4 nstr = '3087' nstr_asc = '0378' nstr_desc = '8730' x = 8352 y = 5 nstr = '8352' nstr_asc = '2358' nstr_desc = '8532' x = 6174 y = 6

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

y = 0 nstr = '0691' nstr_asc = '0169' nstr_desc = '9610' x = 9441 y = 1 nstr = '9441' nstr_asc = '1449' nstr_desc = '9441' x = 7992 y = 2 nstr = '7992' nstr_asc = '2799' nstr_desc = '9972' x = 7173 y = 3 nstr = '7173' nstr_asc = '1377' nstr_desc = '7731' x = 6354 y = 4 nstr = '6354' nstr_asc = '3456' nstr_desc = '6543' x = 3087 y = 5 nstr = '3087' nstr_asc = '0378' nstr_desc = '8730' x = 8352 y = 6 nstr = '8352' nstr_asc = '2358' nstr_desc = '8532' x = 6174 y = 7

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

y = 0 nstr = '3333' nstr_asc = '3333' nstr_desc = '3333' x = 0 y = 1

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

y = 0 nstr = '0001' nstr_asc = '0001' nstr_desc = '1000' x = 999 y = 1 nstr = '0999' nstr_asc = '0999' nstr_desc = '9990' x = 8991 y = 2 nstr = '8991' nstr_asc = '1899' nstr_desc = '9981' x = 8082 y = 3 nstr = '8082' nstr_asc = '0288' nstr_desc = '8820' x = 8532 y = 4 nstr = '8532' nstr_asc = '2358' nstr_desc = '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 nstr = '1234' nstr_asc = '1234' nstr_desc = '4321' x = 3087 y = 1 nstr = '3087' nstr_asc = '0378' nstr_desc = '8730' x = 8352 y = 2 nstr = '8352' nstr_asc = '2358' nstr_desc = '8532' x = 6174 y = 3

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

y = 0 nstr = '3141' nstr_asc = '1134' nstr_desc = '4311' x = 3177 y = 1 nstr = '3177' nstr_asc = '1377' nstr_desc = '7731' x = 6354 y = 2 nstr = '6354' nstr_asc = '3456' nstr_desc = '6543' x = 3087 y = 3 nstr = '3087' nstr_asc = '0378' nstr_desc = '8730' x = 8352 y = 4 nstr = '8352' nstr_asc = '2358' nstr_desc = '8532' x = 6174 y = 5

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

y = 0 nstr = '8080' nstr_asc = '0088' nstr_desc = '8800' x = 8712 y = 1 nstr = '8712' nstr_asc = '1278' nstr_desc = '8721' x = 7443 y = 2 nstr = '7443' nstr_asc = '3447' nstr_desc = '7443' x = 3996 y = 3 nstr = '3996' nstr_asc = '3699' nstr_desc = '9963' x = 6264 y = 4 nstr = '6264' nstr_asc = '2466' nstr_desc = '6642' x = 4176 y = 5 nstr = '4176' nstr_asc = '1467' nstr_desc = '7641' x = 6174 y = 6

Suggested Problems

More from this Author95

Community Treasure Hunt

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

Start Hunting!