Cody

# Problem 166. Kaprekar numbers

Solution 452828

Submitted on 10 Jun 2014 by rifat
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

2   Pass
%% x = 704; tf_correct = false; assert(isequal(kap(x),tf_correct))

n = 3 ds = 4 9 5 6 1 6 a = 4 9 5 a = 495 b = 6 1 6 b = 616 ans = 0

3   Pass
%% x = 9 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 9 tf_correct = 1 n = 1 ds = 8 1 a = 8 a = 8 b = 1 b = 1 ans = 1

4   Pass
%% x = 45 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 45 tf_correct = 1 n = 2 ds = 2 0 2 5 a = 2 0 a = 20 b = 2 5 b = 25 ans = 1

5   Pass
%% x = 55 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 55 tf_correct = 1 n = 2 ds = 3 0 2 5 a = 3 0 a = 30 b = 2 5 b = 25 ans = 1

6   Pass
%% x = 99 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 99 tf_correct = 1 n = 2 ds = 9 8 0 1 a = 9 8 a = 98 b = 0 1 b = 1 ans = 1

7   Pass
%% x = 297 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 297 tf_correct = 1 n = 3 ds = 8 8 2 0 9 a = 8 8 a = 88 b = 2 0 9 b = 209 ans = 1

8   Pass
%% x = 703 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 703 tf_correct = 1 n = 3 ds = 4 9 4 2 0 9 a = 4 9 4 a = 494 b = 2 0 9 b = 209 ans = 1

9   Pass
%% x = 999 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 999 tf_correct = 1 n = 3 ds = 9 9 8 0 0 1 a = 9 9 8 a = 998 b = 0 0 1 b = 1 ans = 1

10   Pass
%% x = 2223 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 2223 tf_correct = 1 n = 4 ds = 4 9 4 1 7 2 9 a = 4 9 4 a = 494 b = 1 7 2 9 b = 1729 ans = 1

11   Pass
%% x = 2728 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 2728 tf_correct = 1 n = 4 ds = 7 4 4 1 9 8 4 a = 7 4 4 a = 744 b = 1 9 8 4 b = 1984 ans = 1

12   Pass
%% x = 4950 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 4950 tf_correct = 1 n = 4 ds = 2 4 5 0 2 5 0 0 a = 2 4 5 0 a = 2450 b = 2 5 0 0 b = 2500 ans = 1

13   Pass
%% x = 5050 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 5050 tf_correct = 1 n = 4 ds = 2 5 5 0 2 5 0 0 a = 2 5 5 0 a = 2550 b = 2 5 0 0 b = 2500 ans = 1

14   Pass
%% x = 7272 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 7272 tf_correct = 1 n = 4 ds = 5 2 8 8 1 9 8 4 a = 5 2 8 8 a = 5288 b = 1 9 8 4 b = 1984 ans = 1

15   Pass
%% x = 7777 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 7777 tf_correct = 1 n = 4 ds = 6 0 4 8 1 7 2 9 a = 6 0 4 8 a = 6048 b = 1 7 2 9 b = 1729 ans = 1

16   Pass
%% x = 9999 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 9999 tf_correct = 1 n = 4 ds = 9 9 9 8 0 0 0 1 a = 9 9 9 8 a = 9998 b = 0 0 0 1 b = 1 ans = 1

17   Pass
%% x = 17344 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 17344 tf_correct = 1 n = 5 ds = 3 0 0 8 1 4 3 3 6 a = 3 0 0 8 a = 3008 b = 1 4 3 3 6 b = 14336 ans = 1

18   Pass
%% x = 22222 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 22222 tf_correct = 1 n = 5 ds = 4 9 3 8 1 7 2 8 4 a = 4 9 3 8 a = 4938 b = 1 7 2 8 4 b = 17284 ans = 1

19   Pass
%% x = 77778 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 77778 tf_correct = 1 n = 5 ds = 6 0 4 9 4 1 7 2 8 4 a = 6 0 4 9 4 a = 60494 b = 1 7 2 8 4 b = 17284 ans = 1

20   Pass
%% x = 82656 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 82656 tf_correct = 1 n = 5 ds = 6 8 3 2 0 1 4 3 3 6 a = 6 8 3 2 0 a = 68320 b = 1 4 3 3 6 b = 14336 ans = 1

21   Pass
%% x = 95121 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 95121 tf_correct = 1 n = 5 ds = 9 0 4 8 0 0 4 6 4 1 a = 9 0 4 8 0 a = 90480 b = 0 4 6 4 1 b = 4641 ans = 1

22   Pass
%% x = 99999 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 99999 tf_correct = 1 n = 5 ds = 9 9 9 9 8 0 0 0 0 1 a = 9 9 9 9 8 a = 99998 b = 0 0 0 0 1 b = 1 ans = 1

23   Pass
%% x = 142857 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 142857 tf_correct = 1 n = 6 ds = 2 0 4 0 8 1 2 2 4 4 9 a = 2 0 4 0 8 a = 20408 b = 1 2 2 4 4 9 b = 122449 ans = 1

24   Pass
%% x = 148149 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 148149 tf_correct = 1 n = 6 ds = 2 1 9 4 8 1 2 6 2 0 1 a = 2 1 9 4 8 a = 21948 b = 1 2 6 2 0 1 b = 126201 ans = 1

25   Pass
%% x = 181819 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 181819 tf_correct = 1 n = 6 ds = 3 3 0 5 8 1 4 8 7 6 1 a = 3 3 0 5 8 a = 33058 b = 1 4 8 7 6 1 b = 148761 ans = 1

26   Pass
%% x = 187110 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 187110 tf_correct = 1 n = 6 ds = 3 5 0 1 0 1 5 2 1 0 0 a = 3 5 0 1 0 a = 35010 b = 1 5 2 1 0 0 b = 152100 ans = 1

27   Pass
%% x = 208495 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 208495 tf_correct = 1 n = 6 ds = 4 3 4 7 0 1 6 5 0 2 5 a = 4 3 4 7 0 a = 43470 b = 1 6 5 0 2 5 b = 165025 ans = 1

28   Pass
%% x = 318682 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 318682 tf_correct = 1 n = 6 ds = 1 0 1 5 5 8 2 1 7 1 2 4 a = 1 0 1 5 5 8 a = 101558 b = 2 1 7 1 2 4 b = 217124 ans = 1

29   Pass
%% x = 329967 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 329967 tf_correct = 1 n = 6 ds = 1 0 8 8 7 8 2 2 1 0 8 9 a = 1 0 8 8 7 8 a = 108878 b = 2 2 1 0 8 9 b = 221089 ans = 1

30   Pass
%% x = 351352 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 351352 tf_correct = 1 n = 6 ds = 1 2 3 4 4 8 2 2 7 9 0 4 a = 1 2 3 4 4 8 a = 123448 b = 2 2 7 9 0 4 b = 227904 ans = 1

31   Pass
%% x = 356643 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 356643 tf_correct = 1 n = 6 ds = 1 2 7 1 9 4 2 2 9 4 4 9 a = 1 2 7 1 9 4 a = 127194 b = 2 2 9 4 4 9 b = 229449 ans = 1

32   Pass
%% x = 390313 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 390313 tf_correct = 1 n = 6 ds = 1 5 2 3 4 4 2 3 7 9 6 9 a = 1 5 2 3 4 4 a = 152344 b = 2 3 7 9 6 9 b = 237969 ans = 1

33   Pass
%% x = 461539 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 461539 tf_correct = 1 n = 6 ds = 2 1 3 0 1 8 2 4 8 5 2 1 a = 2 1 3 0 1 8 a = 213018 b = 2 4 8 5 2 1 b = 248521 ans = 1

34   Pass
%% x = 466830 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 466830 tf_correct = 1 n = 6 ds = 2 1 7 9 3 0 2 4 8 9 0 0 a = 2 1 7 9 3 0 a = 217930 b = 2 4 8 9 0 0 b = 248900 ans = 1

35   Pass
%% x = 499500 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 499500 tf_correct = 1 n = 6 ds = 2 4 9 5 0 0 2 5 0 0 0 0 a = 2 4 9 5 0 0 a = 249500 b = 2 5 0 0 0 0 b = 250000 ans = 1

36   Pass
%% x = 500500 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 500500 tf_correct = 1 n = 6 ds = 2 5 0 5 0 0 2 5 0 0 0 0 a = 2 5 0 5 0 0 a = 250500 b = 2 5 0 0 0 0 b = 250000 ans = 1

37   Pass
%% x = 533170 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 533170 tf_correct = 1 n = 6 ds = 2 8 4 2 7 0 2 4 8 9 0 0 a = 2 8 4 2 7 0 a = 284270 b = 2 4 8 9 0 0 b = 248900 ans = 1

38   Pass
%% x = 538461 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 538461 tf_correct = 1 n = 6 ds = 2 8 9 9 4 0 2 4 8 5 2 1 a = 2 8 9 9 4 0 a = 289940 b = 2 4 8 5 2 1 b = 248521 ans = 1

39   Pass
%% x = 609687 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 609687 tf_correct = 1 n = 6 ds = 3 7 1 7 1 8 2 3 7 9 6 9 a = 3 7 1 7 1 8 a = 371718 b = 2 3 7 9 6 9 b = 237969 ans = 1

40   Pass
%% x = 643357 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 643357 tf_correct = 1 n = 6 ds = 4 1 3 9 0 8 2 2 9 4 4 9 a = 4 1 3 9 0 8 a = 413908 b = 2 2 9 4 4 9 b = 229449 ans = 1

41   Pass
%% x = 648648 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 648648 tf_correct = 1 n = 6 ds = 4 2 0 7 4 4 2 2 7 9 0 4 a = 4 2 0 7 4 4 a = 420744 b = 2 2 7 9 0 4 b = 227904 ans = 1

42   Pass
%% x = 670033 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 670033 tf_correct = 1 n = 6 ds = 4 4 8 9 4 4 2 2 1 0 8 9 a = 4 4 8 9 4 4 a = 448944 b = 2 2 1 0 8 9 b = 221089 ans = 1

43   Pass
%% x = 681318 tf_correct = true assert(isequal(kap(x),tf_correct))

x = 681318 tf_correct = 1 n = 6 ds = 4 6 4 1 9 4 2 1 7 1 2 4 a = 4 6 4 1 9 4 a = 464194 b = 2 1 7 1 2 4 b = 217124 ans = 1

44   Pass
%% x = 681319 tf_correct = false assert(isequal(kap(x),tf_correct))

x = 681319 tf_correct = 0 n = 6 ds = 4 6 4 1 9 5 5 7 9 7 6 1 a = 4 6 4 1 9 5 a = 464195 b = 5 7 9 7 6 1 b = 579761 ans = 0

45   Pass
%% x = 681320 tf_correct = false assert(isequal(kap(x),tf_correct))

x = 681320 tf_correct = 0 n = 6 ds = 4 6 4 1 9 6 9 4 2 4 0 0 a = 4 6 4 1 9 6 a = 464196 b = 9 4 2 4 0 0 b = 942400 ans = 0

### Community Treasure Hunt

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

Start Hunting!