Cody

Problem 68. Kaprekar Steps

Solution 404215

Submitted on 14 Feb 2014 by Simon
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))

u = 3276 v = 3276 x = 5265 i = 1 u = 5265 v = 5265 x = 3996 i = 2 u = 3996 v = 3996 x = 6264 i = 3 u = 6264 v = 6264 x = 4176 i = 4 u = 4176 v = 4176 x = 6174 i = 5

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

u = 3 v = 0003 x = 2997 i = 1 u = 2997 v = 2997 x = 7173 i = 2 u = 7173 v = 7173 x = 6354 i = 3 u = 6354 v = 6354 x = 3087 i = 4 u = 3087 v = 3087 x = 8352 i = 5 u = 8352 v = 8352 x = 6174 i = 6

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

u = 691 v = 0691 x = 9441 i = 1 u = 9441 v = 9441 x = 7992 i = 2 u = 7992 v = 7992 x = 7173 i = 3 u = 7173 v = 7173 x = 6354 i = 4 u = 6354 v = 6354 x = 3087 i = 5 u = 3087 v = 3087 x = 8352 i = 6 u = 8352 v = 8352 x = 6174 i = 7

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

i = Inf

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

u = 1 v = 0001 x = 999 i = 1 u = 999 v = 0999 x = 8991 i = 2 u = 8991 v = 8991 x = 8082 i = 3 u = 8082 v = 8082 x = 8532 i = 4 u = 8532 v = 8532 x = 6174 i = 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))

u = 1234 v = 1234 x = 3087 i = 1 u = 3087 v = 3087 x = 8352 i = 2 u = 8352 v = 8352 x = 6174 i = 3

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

u = 3141 v = 3141 x = 3177 i = 1 u = 3177 v = 3177 x = 6354 i = 2 u = 6354 v = 6354 x = 3087 i = 3 u = 3087 v = 3087 x = 8352 i = 4 u = 8352 v = 8352 x = 6174 i = 5

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

u = 8080 v = 8080 x = 8712 i = 1 u = 8712 v = 8712 x = 7443 i = 2 u = 7443 v = 7443 x = 3996 i = 3 u = 3996 v = 3996 x = 6264 i = 4 u = 6264 v = 6264 x = 4176 i = 5 u = 4176 v = 4176 x = 6174 i = 6

Community Treasure Hunt

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

Start Hunting!