Cody

# Problem 68. Kaprekar Steps

Solution 438282

Submitted on 5 May 2014 by Pascal Geschwill
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))

intmat = Columns 1 through 3 3.00000000000000e+000 2.00000000000000e+000 7.00000000000000e+000 Column 4 6.00000000000000e+000 desc = 7.63200000000000e+003 asc = 2.36700000000000e+003 res = 5.26500000000000e+003 intmat = Columns 1 through 3 5.00000000000000e+000 2.00000000000000e+000 6.00000000000000e+000 Column 4 5.00000000000000e+000 res = 3.99600000000000e+003 intmat = Columns 1 through 3 3.00000000000000e+000 9.00000000000000e+000 9.00000000000000e+000 Column 4 6.00000000000000e+000 res = 6.26400000000000e+003 intmat = Columns 1 through 3 6.00000000000000e+000 2.00000000000000e+000 6.00000000000000e+000 Column 4 4.00000000000000e+000 res = 4.17600000000000e+003 intmat = Columns 1 through 3 4.00000000000000e+000 1.00000000000000e+000 7.00000000000000e+000 Column 4 6.00000000000000e+000 res = 6.17400000000000e+003

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

intmat = 3.00000000000000e+000 intmat = 3.00000000000000e+000 0.00000000000000e+000 intmat = 3.00000000000000e+000 0.00000000000000e+000 0.00000000000000e+000 intmat = Columns 1 through 3 3.00000000000000e+000 0.00000000000000e+000 0.00000000000000e+000 Column 4 0.00000000000000e+000 desc = 3.00000000000000e+003 asc = 3.00000000000000e+000 res = 2.99700000000000e+003 intmat = Columns 1 through 3 2.00000000000000e+000 9.00000000000000e+000 9.00000000000000e+000 Column 4 7.00000000000000e+000 res = 7.17300000000000e+003 intmat = Columns 1 through 3 7.00000000000000e+000 1.00000000000000e+000 7.00000000000000e+000 Column 4 3.00000000000000e+000 res = 6.35400000000000e+003 intmat = Columns 1 through 3 6.00000000000000e+000 3.00000000000000e+000 5.00000000000000e+000 Column 4 4.00000000000000e+000 res = 3.08700000000000e+003 intmat = Columns 1 through 3 3.00000000000000e+000 0.00000000000000e+000 8.00000000000000e+000 Column 4 7.00000000000000e+000 res = 8.35200000000000e+003 intmat = Columns 1 through 3 8.00000000000000e+000 3.00000000000000e+000 5.00000000000000e+000 Column 4 2.00000000000000e+000 res = 6.17400000000000e+003

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

intmat = 6.00000000000000e+000 9.00000000000000e+000 1.00000000000000e+000 intmat = Columns 1 through 3 6.00000000000000e+000 9.00000000000000e+000 1.00000000000000e+000 Column 4 0.00000000000000e+000 desc = 9.61000000000000e+003 asc = 169.000000000000e+000 res = 9.44100000000000e+003 intmat = Columns 1 through 3 9.00000000000000e+000 4.00000000000000e+000 4.00000000000000e+000 Column 4 1.00000000000000e+000 res = 7.99200000000000e+003 intmat = Columns 1 through 3 7.00000000000000e+000 9.00000000000000e+000 9.00000000000000e+000 Column 4 2.00000000000000e+000 res = 7.17300000000000e+003 intmat = Columns 1 through 3 7.00000000000000e+000 1.00000000000000e+000 7.00000000000000e+000 Column 4 3.00000000000000e+000 res = 6.35400000000000e+003 intmat = Columns 1 through 3 6.00000000000000e+000 3.00000000000000e+000 5.00000000000000e+000 Column 4 4.00000000000000e+000 res = 3.08700000000000e+003 intmat = Columns 1 through 3 3.00000000000000e+000 0.00000000000000e+000 8.00000000000000e+000 Column 4 7.00000000000000e+000 res = 8.35200000000000e+003 intmat = Columns 1 through 3 8.00000000000000e+000 3.00000000000000e+000 5.00000000000000e+000 Column 4 2.00000000000000e+000 res = 6.17400000000000e+003

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

intmat = Columns 1 through 3 3.00000000000000e+000 3.00000000000000e+000 3.00000000000000e+000 Column 4 3.00000000000000e+000 desc = 3.33300000000000e+003 asc = 3.33300000000000e+003 res = 0.00000000000000e+000

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

intmat = 1.00000000000000e+000 intmat = 1.00000000000000e+000 0.00000000000000e+000 intmat = 1.00000000000000e+000 0.00000000000000e+000 0.00000000000000e+000 intmat = Columns 1 through 3 1.00000000000000e+000 0.00000000000000e+000 0.00000000000000e+000 Column 4 0.00000000000000e+000 desc = 1.00000000000000e+003 asc = 1.00000000000000e+000 res = 999.000000000000e+000 intmat = 9.00000000000000e+000 9.00000000000000e+000 9.00000000000000e+000 res = 8.99100000000000e+003 intmat = Columns 1 through 3 8.00000000000000e+000 9.00000000000000e+000 9.00000000000000e+000 Column 4 1.00000000000000e+000 res = 8.08200000000000e+003 intmat = Columns 1 through 3 8.00000000000000e+000 0.00000000000000e+000 8.00000000000000e+000 Column 4 2.00000000000000e+000 res = 8.53200000000000e+003 intmat = Columns 1 through 3 8.00000000000000e+000 5.00000000000000e+000 3.00000000000000e+000 Column 4 2.00000000000000e+000 res = 6.17400000000000e+003

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

intmat = Columns 1 through 3 6.00000000000000e+000 1.00000000000000e+000 7.00000000000000e+000 Column 4 4.00000000000000e+000 desc = 7.64100000000000e+003 asc = 1.46700000000000e+003 res = 6.17400000000000e+003

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

intmat = Columns 1 through 3 1.00000000000000e+000 2.00000000000000e+000 3.00000000000000e+000 Column 4 4.00000000000000e+000 desc = 4.32100000000000e+003 asc = 1.23400000000000e+003 res = 3.08700000000000e+003 intmat = Columns 1 through 3 3.00000000000000e+000 0.00000000000000e+000 8.00000000000000e+000 Column 4 7.00000000000000e+000 res = 8.35200000000000e+003 intmat = Columns 1 through 3 8.00000000000000e+000 3.00000000000000e+000 5.00000000000000e+000 Column 4 2.00000000000000e+000 res = 6.17400000000000e+003

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

intmat = Columns 1 through 3 3.00000000000000e+000 1.00000000000000e+000 4.00000000000000e+000 Column 4 1.00000000000000e+000 desc = 4.31100000000000e+003 asc = 1.13400000000000e+003 res = 3.17700000000000e+003 intmat = Columns 1 through 3 3.00000000000000e+000 1.00000000000000e+000 7.00000000000000e+000 Column 4 7.00000000000000e+000 res = 6.35400000000000e+003 intmat = Columns 1 through 3 6.00000000000000e+000 3.00000000000000e+000 5.00000000000000e+000 Column 4 4.00000000000000e+000 res = 3.08700000000000e+003 intmat = Columns 1 through 3 3.00000000000000e+000 0.00000000000000e+000 8.00000000000000e+000 Column 4 7.00000000000000e+000 res = 8.35200000000000e+003 intmat = Columns 1 through 3 8.00000000000000e+000 3.00000000000000e+000 5.00000000000000e+000 Column 4 2.00000000000000e+000 res = 6.17400000000000e+003

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

intmat = Columns 1 through 3 8.00000000000000e+000 0.00000000000000e+000 8.00000000000000e+000 Column 4 0.00000000000000e+000 desc = 8.80000000000000e+003 asc = 88.0000000000000e+000 res = 8.71200000000000e+003 intmat = Columns 1 through 3 8.00000000000000e+000 7.00000000000000e+000 1.00000000000000e+000 Column 4 2.00000000000000e+000 res = 7.44300000000000e+003 intmat = Columns 1 through 3 7.00000000000000e+000 4.00000000000000e+000 4.00000000000000e+000 Column 4 3.00000000000000e+000 res = 3.99600000000000e+003 intmat = Columns 1 through 3 3.00000000000000e+000 9.00000000000000e+000 9.00000000000000e+000 Column 4 6.00000000000000e+000 res = 6.26400000000000e+003 intmat = Columns 1 through 3 6.00000000000000e+000 2.00000000000000e+000 6.00000000000000e+000 Column 4 4.00000000000000e+000 res = 4.17600000000000e+003 intmat = Columns 1 through 3 4.00000000000000e+000 1.00000000000000e+000 7.00000000000000e+000 Column 4 6.00000000000000e+000 res = 6.17400000000000e+003