Cody

Problem 166. Kaprekar numbers

Solution 2904065

Submitted on 2 Sep 2020 by Jerry Wright
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))

sqx = 256 nDigs = 3 eq_parts = 10 sum = 31 eq_parts = 100 sum = 58 eq_parts = 1000 sum = 256

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

sqx = 495616 nDigs = 6 eq_parts = 10 sum = 49567 eq_parts = 100 sum = 4972 eq_parts = 1000 sum = 1111 eq_parts = 10000 sum = 5665 eq_parts = 100000 sum = 95620 eq_parts = 1000000 sum = 495616

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

x = 9 tf_correct = logical 1 sqx = 81 nDigs = 2 eq_parts = 10 sum = 9 tf = logical 1

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

x = 45 tf_correct = logical 1 sqx = 2025 nDigs = 4 eq_parts = 10 sum = 207 eq_parts = 100 sum = 45 tf = logical 1

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

x = 55 tf_correct = logical 1 sqx = 3025 nDigs = 4 eq_parts = 10 sum = 307 eq_parts = 100 sum = 55 tf = logical 1

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

x = 99 tf_correct = logical 1 sqx = 9801 nDigs = 4 eq_parts = 10 sum = 981 eq_parts = 100 sum = 99 tf = logical 1

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

x = 297 tf_correct = logical 1 sqx = 88209 nDigs = 5 eq_parts = 10 sum = 8829 eq_parts = 100 sum = 891 eq_parts = 1000 sum = 297 tf = logical 1

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

x = 703 tf_correct = logical 1 sqx = 494209 nDigs = 6 eq_parts = 10 sum = 49429 eq_parts = 100 sum = 4951 eq_parts = 1000 sum = 703 tf = logical 1

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

x = 999 tf_correct = logical 1 sqx = 998001 nDigs = 6 eq_parts = 10 sum = 99801 eq_parts = 100 sum = 9981 eq_parts = 1000 sum = 999 tf = logical 1

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

x = 2223 tf_correct = logical 1 sqx = 4941729 nDigs = 7 eq_parts = 10 sum = 494181 eq_parts = 100 sum = 49446 eq_parts = 1000 sum = 5670 eq_parts = 10000 sum = 2223 tf = logical 1

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

x = 2728 tf_correct = logical 1 sqx = 7441984 nDigs = 7 eq_parts = 10 sum = 744202 eq_parts = 100 sum = 74503 eq_parts = 1000 sum = 8425 eq_parts = 10000 sum = 2728 tf = logical 1

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

x = 4950 tf_correct = logical 1 sqx = 24502500 nDigs = 8 eq_parts = 10 sum = 2450250 eq_parts = 100 sum = 245025 eq_parts = 1000 sum = 25002 eq_parts = 10000 sum = 4950 tf = logical 1

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

x = 5050 tf_correct = logical 1 sqx = 25502500 nDigs = 8 eq_parts = 10 sum = 2550250 eq_parts = 100 sum = 255025 eq_parts = 1000 sum = 26002 eq_parts = 10000 sum = 5050 tf = logical 1

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

x = 7272 tf_correct = logical 1 sqx = 52881984 nDigs = 8 eq_parts = 10 sum = 5288202 eq_parts = 100 sum = 528903 eq_parts = 1000 sum = 53865 eq_parts = 10000 sum = 7272 tf = logical 1

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

x = 7777 tf_correct = logical 1 sqx = 60481729 nDigs = 8 eq_parts = 10 sum = 6048181 eq_parts = 100 sum = 604846 eq_parts = 1000 sum = 61210 eq_parts = 10000 sum = 7777 tf = logical 1

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

x = 9999 tf_correct = logical 1 sqx = 99980001 nDigs = 8 eq_parts = 10 sum = 9998001 eq_parts = 100 sum = 999801 eq_parts = 1000 sum = 99981 eq_parts = 10000 sum = 9999 tf = logical 1

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

x = 17344 tf_correct = logical 1 sqx = 300814336 nDigs = 9 eq_parts = 10 sum = 30081439 eq_parts = 100 sum = 3008179 eq_parts = 1000 sum = 301150 eq_parts = 10000 sum = 34417 eq_parts = 100000 sum = 17344 tf = logical 1

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

x = 22222 tf_correct = logical 1 sqx = 493817284 nDigs = 9 eq_parts = 10 sum = 49381732 eq_parts = 100 sum = 4938256 eq_parts = 1000 sum = 494101 eq_parts = 10000 sum = 56665 eq_parts = 100000 sum = 22222 tf = logical 1

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

x = 77778 tf_correct = logical 1 sqx = 6.0494e+09 nDigs = 10 eq_parts = 10 sum = 604941732 eq_parts = 100 sum = 60494256 eq_parts = 1000 sum = 6049701 eq_parts = 10000 sum = 612225 eq_parts = 100000 sum = 77778 tf = logical 1

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

x = 82656 tf_correct = logical 1 sqx = 6.8320e+09 nDigs = 10 eq_parts = 10 sum = 683201439 eq_parts = 100 sum = 68320179 eq_parts = 1000 sum = 6832350 eq_parts = 10000 sum = 687537 eq_parts = 100000 sum = 82656 tf = logical 1

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

x = 95121 tf_correct = logical 1 sqx = 9.0480e+09 nDigs = 10 eq_parts = 10 sum = 904800465 eq_parts = 100 sum = 90480087 eq_parts = 1000 sum = 9048645 eq_parts = 10000 sum = 909441 eq_parts = 100000 sum = 95121 tf = logical 1

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

x = 99999 tf_correct = logical 1 sqx = 9.9998e+09 nDigs = 10 eq_parts = 10 sum = 999980001 eq_parts = 100 sum = 99998001 eq_parts = 1000 sum = 9999801 eq_parts = 10000 sum = 999981 eq_parts = 100000 sum = 99999 tf = logical 1

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

x = 142857 tf_correct = logical 1 sqx = 2.0408e+10 nDigs = 11 eq_parts = 10 sum = 2.0408e+09 eq_parts = 100 sum = 204081273 eq_parts = 1000 sum = 20408571 eq_parts = 10000 sum = 2043261 eq_parts = 100000 sum = 226530 eq_parts = 1000000 sum = 142857 tf = logical 1

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

x = 148149 tf_correct = logical 1 sqx = 2.1948e+10 nDigs = 11 eq_parts = 10 sum = 2.1948e+09 eq_parts = 100 sum = 219481263 eq_parts = 1000 sum = 21948327 eq_parts = 10000 sum = 2201013 eq_parts = 100000 sum = 245682 eq_parts = 1000000 sum = 148149 tf = logical 1

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

x = 181819 tf_correct = logical 1 sqx = 3.3058e+10 nDigs = 11 eq_parts = 10 sum = 3.3058e+09 eq_parts = 100 sum = 330581548 eq_parts = 1000 sum = 33058909 eq_parts = 10000 sum = 3314575 eq_parts = 100000 sum = 379342 eq_parts = 1000000 sum = 181819 tf = logical 1

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

x = 187110 tf_correct = logical 1 sqx = 3.5010e+10 nDigs = 11 eq_parts = 10 sum = 3.5010e+09 eq_parts = 100 sum = 350101521 eq_parts = 1000 sum = 35010252 eq_parts = 10000 sum = 3503115 eq_parts = 100000 sum = 402201 eq_parts = 1000000 sum = 187110 tf = logical 1

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

x = 208495 tf_correct = logical 1 sqx = 4.3470e+10 nDigs = 11 eq_parts = 10 sum = 4.3470e+09 eq_parts = 100 sum = 434701675 eq_parts = 1000 sum = 43470190 eq_parts = 10000 sum = 4352041 eq_parts = 100000 sum = 499726 eq_parts = 1000000 sum = 208495 tf = logical 1

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

x = 318682 tf_correct = logical 1 sqx = 1.0156e+11 nDigs = 12 eq_parts = 10 sum = 1.0156e+10 eq_parts = 100 sum = 1.0156e+09 eq_parts = 1000 sum = 101558341 eq_parts = 10000 sum = 10162945 eq_parts = 100000 sum = 1032706 eq_parts = 1000000 sum = 318682 tf = logical 1

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

x = 329967 tf_correct = logical 1 sqx = 1.0888e+11 nDigs = 12 eq_parts = 10 sum = 1.0888e+10 eq_parts = 100 sum = 1.0888e+09 eq_parts = 1000 sum = 108878310 eq_parts = 10000 sum = 10888911 eq_parts = 100000 sum = 1109871 eq_parts = 1000000 sum = 329967 tf = logical 1

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

x = 351352 tf_correct = logical 1 sqx = 1.2345e+11 nDigs = 12 eq_parts = 10 sum = 1.2345e+10 eq_parts = 100 sum = 1.2345e+09 eq_parts = 1000 sum = 123449131 eq_parts = 10000 sum = 12352726 eq_parts = 100000 sum = 1262386 eq_parts = 1000000 sum = 351352 tf = logical 1

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

x = 356643 tf_correct = logical 1 sqx = 1.2719e+11 nDigs = 12 eq_parts = 10 sum = 1.2719e+10 eq_parts = 100 sum = 1.2719e+09 eq_parts = 1000 sum = 127194678 eq_parts = 10000 sum = 12728871 eq_parts = 100000 sum = 1301391 eq_parts = 1000000 sum = 356643 tf = logical 1

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

x = 390313 tf_correct = logical 1 sqx = 1.5234e+11 nDigs = 12 eq_parts = 10 sum = 1.5234e+10 eq_parts = 100 sum = 1.5234e+09 eq_parts = 1000 sum = 152345206 eq_parts = 10000 sum = 15242392 eq_parts = 100000 sum = 1561411 eq_parts = 1000000 sum = 390313 tf = logical 1

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

x = 461539 tf_correct = logical 1 sqx = 2.1302e+11 nDigs = 12 eq_parts = 10 sum = 2.1302e+10 eq_parts = 100 sum = 2.1302e+09 eq_parts = 1000 sum = 213018769 eq_parts = 10000 sum = 21310345 eq_parts = 100000 sum = 2178703 eq_parts = 1000000 sum = 461539 tf = logical 1

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

x = 466830 tf_correct = logical 1 sqx = 2.1793e+11 nDigs = 12 eq_parts = 10 sum = 2.1793e+10 eq_parts = 100 sum = 2.1793e+09 eq_parts = 1000 sum = 217931148 eq_parts = 10000 sum = 21801924 eq_parts = 100000 sum = 2228202 eq_parts = 1000000 sum = 466830 tf = logical 1

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

x = 499500 tf_correct = logical 1 sqx = 2.4950e+11 nDigs = 12 eq_parts = 10 sum = 2.4950e+10 eq_parts = 100 sum = 2.4950e+09 eq_parts = 1000 sum = 249500250 eq_parts = 10000 sum = 24950025 eq_parts = 100000 sum = 2545002 eq_parts = 1000000 sum = 499500 tf = logical 1

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

x = 500500 tf_correct = logical 1 sqx = 2.5050e+11 nDigs = 12 eq_parts = 10 sum = 2.5050e+10 eq_parts = 100 sum = 2.5050e+09 eq_parts = 1000 sum = 250500250 eq_parts = 10000 sum = 25050025 eq_parts = 100000 sum = 2555002 eq_parts = 1000000 sum = 500500 tf = logical 1

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

x = 533170 tf_correct = logical 1 sqx = 2.8427e+11 nDigs = 12 eq_parts = 10 sum = 2.8427e+10 eq_parts = 100 sum = 2.8427e+09 eq_parts = 1000 sum = 284271148 eq_parts = 10000 sum = 28435924 eq_parts = 100000 sum = 2891602 eq_parts = 1000000 sum = 533170 tf = logical 1

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

x = 538461 tf_correct = logical 1 sqx = 2.8994e+11 nDigs = 12 eq_parts = 10 sum = 2.8994e+10 eq_parts = 100 sum = 2.8994e+09 eq_parts = 1000 sum = 289940769 eq_parts = 10000 sum = 29002545 eq_parts = 100000 sum = 2947923 eq_parts = 1000000 sum = 538461 tf = logical 1

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

x = 609687 tf_correct = logical 1 sqx = 3.7172e+11 nDigs = 12 eq_parts = 10 sum = 3.7172e+10 eq_parts = 100 sum = 3.7172e+09 eq_parts = 1000 sum = 371719206 eq_parts = 10000 sum = 37179792 eq_parts = 100000 sum = 3755151 eq_parts = 1000000 sum = 609687 tf = logical 1

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

x = 643357 tf_correct = logical 1 sqx = 4.1391e+11 nDigs = 12 eq_parts = 10 sum = 4.1391e+10 eq_parts = 100 sum = 4.1391e+09 eq_parts = 1000 sum = 413908678 eq_parts = 10000 sum = 41400271 eq_parts = 100000 sum = 4168531 eq_parts = 1000000 sum = 643357 tf = logical 1

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

x = 648648 tf_correct = logical 1 sqx = 4.2074e+11 nDigs = 12 eq_parts = 10 sum = 4.2074e+10 eq_parts = 100 sum = 4.2074e+09 eq_parts = 1000 sum = 420745131 eq_parts = 10000 sum = 42082326 eq_parts = 100000 sum = 4235346 eq_parts = 1000000 sum = 648648 tf = logical 1

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

x = 670033 tf_correct = logical 1 sqx = 4.4894e+11 nDigs = 12 eq_parts = 10 sum = 4.4894e+10 eq_parts = 100 sum = 4.4894e+09 eq_parts = 1000 sum = 448944310 eq_parts = 10000 sum = 44895511 eq_parts = 100000 sum = 4510531 eq_parts = 1000000 sum = 670033 tf = logical 1

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

x = 681318 tf_correct = logical 1 sqx = 4.6419e+11 nDigs = 12 eq_parts = 10 sum = 4.6419e+10 eq_parts = 100 sum = 4.6419e+09 eq_parts = 1000 sum = 464194341 eq_parts = 10000 sum = 46426545 eq_parts = 100000 sum = 4659066 eq_parts = 1000000 sum = 681318 tf = logical 1

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

x = 681319 tf_correct = logical 0 sqx = 4.6420e+11 nDigs = 12 eq_parts = 10 sum = 4.6420e+10 eq_parts = 100 sum = 4.6420e+09 eq_parts = 1000 sum = 464196340 eq_parts = 10000 sum = 46429318 eq_parts = 100000 sum = 4721716 eq_parts = 1000000 sum = 1043956 eq_parts = 10000000 sum = 5626180 eq_parts = 100000000 sum = 95584402 eq_parts = 1.0000e+09 sum = 195580225 eq_parts = 1.0000e+10 sum = 4.1956e+09 eq_parts = 1.0000e+11 sum = 6.4196e+10 eq_parts = 1.0000e+12 sum = 4.6420e+11

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

x = 681320 tf_correct = logical 0 sqx = 4.6420e+11 nDigs = 12 eq_parts = 10 sum = 4.6420e+10 eq_parts = 100 sum = 4.6420e+09 eq_parts = 1000 sum = 464197342 eq_parts = 10000 sum = 46422094 eq_parts = 100000 sum = 4684369 eq_parts = 1000000 sum = 1406596 eq_parts = 10000000 sum = 6988819 eq_parts = 100000000 sum = 96947041 eq_parts = 1.0000e+09 sum = 196942864 eq_parts = 1.0000e+10 sum = 4.1969e+09 eq_parts = 1.0000e+11 sum = 6.4197e+10 eq_parts = 1.0000e+12 sum = 4.6420e+11

Community Treasure Hunt

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

Start Hunting!