Cody

# Problem 166. Kaprekar numbers

Solution 1876886

Submitted on 17 Jul 2019 by Nikolaos Nikolaou
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 = 16; tf_correct = false; assert(isequal(kap(x),tf_correct))

y1 = 2 y2 = 5 6 k1 = 2 k2 = 56 k = 58 ans = 8 5 tf = 0

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

y1 = 4 9 5 y2 = 6 1 6 k1 = 495 k2 = 616 k = 1111 ans = 1 1 1 1 tf = 0

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

x = 9 tf_correct = logical 1 y1 = 8 y2 = 1 k1 = 8 k2 = 1 k = 9 ans = 9 tf = 1

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

x = 45 tf_correct = logical 1 y1 = 2 0 y2 = 2 5 k1 = 20 k2 = 25 k = 45 ans = 5 4 tf = 1

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

x = 55 tf_correct = logical 1 y1 = 3 0 y2 = 2 5 k1 = 30 k2 = 25 k = 55 ans = 5 5 tf = 1

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

x = 99 tf_correct = logical 1 y1 = 9 8 y2 = 0 1 k1 = 98 k2 = 1 k = 99 ans = 9 9 tf = 1

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

x = 297 tf_correct = logical 1 y1 = 8 8 y2 = 2 0 9 k1 = 88 k2 = 209 k = 297 ans = 7 9 2 tf = 1

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

x = 703 tf_correct = logical 1 y1 = 4 9 4 y2 = 2 0 9 k1 = 494 k2 = 209 k = 703 ans = 3 0 7 tf = 1

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

x = 999 tf_correct = logical 1 y1 = 9 9 8 y2 = 0 0 1 k1 = 998 k2 = 1 k = 999 ans = 9 9 9 tf = 1

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

x = 2223 tf_correct = logical 1 y1 = 4 9 4 y2 = 1 7 2 9 k1 = 494 k2 = 1729 k = 2223 ans = 3 2 2 2 tf = 1

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

x = 2728 tf_correct = logical 1 y1 = 7 4 4 y2 = 1 9 8 4 k1 = 744 k2 = 1984 k = 2728 ans = 8 2 7 2 tf = 1

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

x = 4950 tf_correct = logical 1 y1 = 2 4 5 0 y2 = 2 5 0 0 k1 = 2450 k2 = 2500 k = 4950 ans = 0 5 9 4 tf = 1

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

x = 5050 tf_correct = logical 1 y1 = 2 5 5 0 y2 = 2 5 0 0 k1 = 2550 k2 = 2500 k = 5050 ans = 0 5 0 5 tf = 1

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

x = 7272 tf_correct = logical 1 y1 = 5 2 8 8 y2 = 1 9 8 4 k1 = 5288 k2 = 1984 k = 7272 ans = 2 7 2 7 tf = 1

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

x = 7777 tf_correct = logical 1 y1 = 6 0 4 8 y2 = 1 7 2 9 k1 = 6048 k2 = 1729 k = 7777 ans = 7 7 7 7 tf = 1

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

x = 9999 tf_correct = logical 1 y1 = 9 9 9 8 y2 = 0 0 0 1 k1 = 9998 k2 = 1 k = 9999 ans = 9 9 9 9 tf = 1

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

x = 17344 tf_correct = logical 1 y1 = 3 0 0 8 y2 = 1 4 3 3 6 k1 = 3008 k2 = 14336 k = 17344 ans = 4 4 3 7 1 tf = 1

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

x = 22222 tf_correct = logical 1 y1 = 4 9 3 8 y2 = 1 7 2 8 4 k1 = 4938 k2 = 17284 k = 22222 ans = 2 2 2 2 2 tf = 1

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

x = 77778 tf_correct = logical 1 y1 = 6 0 4 9 4 y2 = 1 7 2 8 4 k1 = 60494 k2 = 17284 k = 77778 ans = 8 7 7 7 7 tf = 1

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

x = 82656 tf_correct = logical 1 y1 = 6 8 3 2 0 y2 = 1 4 3 3 6 k1 = 68320 k2 = 14336 k = 82656 ans = 6 5 6 2 8 tf = 1

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

x = 95121 tf_correct = logical 1 y1 = 9 0 4 8 0 y2 = 0 4 6 4 1 k1 = 90480 k2 = 4641 k = 95121 ans = 1 2 1 5 9 tf = 1

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

x = 99999 tf_correct = logical 1 y1 = 9 9 9 9 8 y2 = 0 0 0 0 1 k1 = 99998 k2 = 1 k = 99999 ans = 9 9 9 9 9 tf = 1

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

x = 142857 tf_correct = logical 1 y1 = 2 0 4 0 8 y2 = 1 2 2 4 4 9 k1 = 20408 k2 = 122449 k = 142857 ans = 7 5 8 2 4 1 tf = 1

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

x = 148149 tf_correct = logical 1 y1 = 2 1 9 4 8 y2 = 1 2 6 2 0 1 k1 = 21948 k2 = 126201 k = 148149 ans = 9 4 1 8 4 1 tf = 1

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

x = 181819 tf_correct = logical 1 y1 = 3 3 0 5 8 y2 = 1 4 8 7 6 1 k1 = 33058 k2 = 148761 k = 181819 ans = 9 1 8 1 8 1 tf = 1

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

x = 187110 tf_correct = logical 1 y1 = 3 5 0 1 0 y2 = 1 5 2 1 0 0 k1 = 35010 k2 = 152100 k = 187110 ans = 0 1 1 7 8 1 tf = 1

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

x = 208495 tf_correct = logical 1 y1 = 4 3 4 7 0 y2 = 1 6 5 0 2 5 k1 = 43470 k2 = 165025 k = 208495 ans = 5 9 4 8 0 2 tf = 1

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

x = 318682 tf_correct = logical 1 y1 = 1 0 1 5 5 8 y2 = 2 1 7 1 2 4 k1 = 101558 k2 = 217124 k = 318682 ans = 2 8 6 8 1 3 tf = 1

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

x = 329967 tf_correct = logical 1 y1 = 1 0 8 8 7 8 y2 = 2 2 1 0 8 9 k1 = 108878 k2 = 221089 k = 329967 ans = 7 6 9 9 2 3 tf = 1

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

x = 351352 tf_correct = logical 1 y1 = 1 2 3 4 4 8 y2 = 2 2 7 9 0 4 k1 = 123448 k2 = 227904 k = 351352 ans = 2 5 3 1 5 3 tf = 1

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

x = 356643 tf_correct = logical 1 y1 = 1 2 7 1 9 4 y2 = 2 2 9 4 4 9 k1 = 127194 k2 = 229449 k = 356643 ans = 3 4 6 6 5 3 tf = 1

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

x = 390313 tf_correct = logical 1 y1 = 1 5 2 3 4 4 y2 = 2 3 7 9 6 9 k1 = 152344 k2 = 237969 k = 390313 ans = 3 1 3 0 9 3 tf = 1

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

x = 461539 tf_correct = logical 1 y1 = 2 1 3 0 1 8 y2 = 2 4 8 5 2 1 k1 = 213018 k2 = 248521 k = 461539 ans = 9 3 5 1 6 4 tf = 1

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

x = 466830 tf_correct = logical 1 y1 = 2 1 7 9 3 0 y2 = 2 4 8 9 0 0 k1 = 217930 k2 = 248900 k = 466830 ans = 0 3 8 6 6 4 tf = 1

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

x = 499500 tf_correct = logical 1 y1 = 2 4 9 5 0 0 y2 = 2 5 0 0 0 0 k1 = 249500 k2 = 250000 k = 499500 ans = 0 0 5 9 9 4 tf = 1

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

x = 500500 tf_correct = logical 1 y1 = 2 5 0 5 0 0 y2 = 2 5 0 0 0 0 k1 = 250500 k2 = 250000 k = 500500 ans = 0 0 5 0 0 5 tf = 1

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

x = 533170 tf_correct = logical 1 y1 = 2 8 4 2 7 0 y2 = 2 4 8 9 0 0 k1 = 284270 k2 = 248900 k = 533170 ans = 0 7 1 3 3 5 tf = 1

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

x = 538461 tf_correct = logical 1 y1 = 2 8 9 9 4 0 y2 = 2 4 8 5 2 1 k1 = 289940 k2 = 248521 k = 538461 ans = 1 6 4 8 3 5 tf = 1

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

x = 609687 tf_correct = logical 1 y1 = 3 7 1 7 1 8 y2 = 2 3 7 9 6 9 k1 = 371718 k2 = 237969 k = 609687 ans = 7 8 6 9 0 6 tf = 1

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

x = 643357 tf_correct = logical 1 y1 = 4 1 3 9 0 8 y2 = 2 2 9 4 4 9 k1 = 413908 k2 = 229449 k = 643357 ans = 7 5 3 3 4 6 tf = 1

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

x = 648648 tf_correct = logical 1 y1 = 4 2 0 7 4 4 y2 = 2 2 7 9 0 4 k1 = 420744 k2 = 227904 k = 648648 ans = 8 4 6 8 4 6 tf = 1

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

x = 670033 tf_correct = logical 1 y1 = 4 4 8 9 4 4 y2 = 2 2 1 0 8 9 k1 = 448944 k2 = 221089 k = 670033 ans = 3 3 0 0 7 6 tf = 1

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

x = 681318 tf_correct = logical 1 y1 = 4 6 4 1 9 4 y2 = 2 1 7 1 2 4 k1 = 464194 k2 = 217124 k = 681318 ans = 8 1 3 1 8 6 tf = 1

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

x = 681319 tf_correct = logical 0 y1 = 4 6 4 1 9 5 y2 = 5 7 9 7 6 1 k1 = 464195 k2 = 579761 k = 1043956 ans = 6 5 9 3 4 0 1 tf = 0

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

x = 681320 tf_correct = logical 0 y1 = 4 6 4 1 9 6 y2 = 9 4 2 4 0 0 k1 = 464196 k2 = 942400 k = 1406596 ans = 6 9 5 6 0 4 1 tf = 0

### Community Treasure Hunt

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

Start Hunting!