Cody

Problem 166. Kaprekar numbers

Solution 475606

Submitted on 20 Jul 2014 by Abdullah Caliskan
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))

k = 495616 l = 6 k2 = 616 k3 = 61 k1 = 495 k2 = 616 k3 = 61 ans = 0

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

x = 9 tf_correct = 1 k = 81 l = 2 k2 = 1 k3 = Empty string: 1-by-0 k1 = 8 k2 = 1 k3 = [] ans = 1

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

x = 45 tf_correct = 1 k = 2025 l = 4 k2 = 25 k3 = 2 k1 = 20 k2 = 25 k3 = 2 ans = 1

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

x = 55 tf_correct = 1 k = 3025 l = 4 k2 = 25 k3 = 2 k1 = 30 k2 = 25 k3 = 2 ans = 1

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

x = 99 tf_correct = 1 k = 9801 l = 4 k2 = 01 k3 = 0 k1 = 98 k2 = 1 k3 = 0 ans = 1

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

x = 297 tf_correct = 1 k = 88209 l = 5 k1 = 88 k2 = 209 k3 = 20 k1 = 88 k2 = 209 k3 = 20 ans = 1

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

x = 703 tf_correct = 1 k = 494209 l = 6 k2 = 209 k3 = 20 k1 = 494 k2 = 209 k3 = 20 ans = 1

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

x = 999 tf_correct = 1 k = 998001 l = 6 k2 = 001 k3 = 00 k1 = 998 k2 = 1 k3 = 0 ans = 1

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

x = 2223 tf_correct = 1 k = 4941729 l = 7 k1 = 494 k2 = 1729 k3 = 172 k1 = 494 k2 = 1729 k3 = 172 ans = 1

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

x = 2728 tf_correct = 1 k = 7441984 l = 7 k1 = 744 k2 = 1984 k3 = 198 k1 = 744 k2 = 1984 k3 = 198 ans = 1

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

x = 4950 tf_correct = 1 k = 24502500 l = 8 k2 = 2500 k3 = 250 k1 = 2450 k2 = 2500 k3 = 250 ans = 1

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

x = 5050 tf_correct = 1 k = 25502500 l = 8 k2 = 2500 k3 = 250 k1 = 2550 k2 = 2500 k3 = 250 ans = 1

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

x = 7272 tf_correct = 1 k = 52881984 l = 8 k2 = 1984 k3 = 198 k1 = 5288 k2 = 1984 k3 = 198 ans = 1

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

x = 7777 tf_correct = 1 k = 60481729 l = 8 k2 = 1729 k3 = 172 k1 = 6048 k2 = 1729 k3 = 172 ans = 1

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

x = 9999 tf_correct = 1 k = 99980001 l = 8 k2 = 0001 k3 = 000 k1 = 9998 k2 = 1 k3 = 0 ans = 1

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

x = 17344 tf_correct = 1 k = 300814336 l = 9 k1 = 3008 k2 = 14336 k3 = 1433 k1 = 3008 k2 = 14336 k3 = 1433 ans = 1

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

x = 22222 tf_correct = 1 k = 493817284 l = 9 k1 = 4938 k2 = 17284 k3 = 1728 k1 = 4938 k2 = 17284 k3 = 1728 ans = 1

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

x = 77778 tf_correct = 1 k = 6049417284 l = 10 k2 = 17284 k3 = 1728 k1 = 60494 k2 = 17284 k3 = 1728 ans = 1

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

x = 82656 tf_correct = 1 k = 6832014336 l = 10 k2 = 14336 k3 = 1433 k1 = 68320 k2 = 14336 k3 = 1433 ans = 1

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

x = 95121 tf_correct = 1 k = 9048004641 l = 10 k2 = 04641 k3 = 0464 k1 = 90480 k2 = 4641 k3 = 464 ans = 1

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

x = 99999 tf_correct = 1 k = 9999800001 l = 10 k2 = 00001 k3 = 0000 k1 = 99998 k2 = 1 k3 = 0 ans = 1

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

x = 142857 tf_correct = 1 k = 20408122449 l = 11 k1 = 20408 k2 = 122449 k3 = 12244 k1 = 20408 k2 = 122449 k3 = 12244 ans = 1

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

x = 148149 tf_correct = 1 k = 21948126201 l = 11 k1 = 21948 k2 = 126201 k3 = 12620 k1 = 21948 k2 = 126201 k3 = 12620 ans = 1

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

x = 181819 tf_correct = 1 k = 33058148761 l = 11 k1 = 33058 k2 = 148761 k3 = 14876 k1 = 33058 k2 = 148761 k3 = 14876 ans = 1

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

x = 187110 tf_correct = 1 k = 35010152100 l = 11 k1 = 35010 k2 = 152100 k3 = 15210 k1 = 35010 k2 = 152100 k3 = 15210 ans = 1

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

x = 208495 tf_correct = 1 k = 43470165025 l = 11 k1 = 43470 k2 = 165025 k3 = 16502 k1 = 43470 k2 = 165025 k3 = 16502 ans = 1

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

x = 318682 tf_correct = 1 k = 101558217124 l = 12 k2 = 217124 k3 = 21712 k1 = 101558 k2 = 217124 k3 = 21712 ans = 1

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

x = 329967 tf_correct = 1 k = 108878221089 l = 12 k2 = 221089 k3 = 22108 k1 = 108878 k2 = 221089 k3 = 22108 ans = 1

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

x = 351352 tf_correct = 1 k = 123448227904 l = 12 k2 = 227904 k3 = 22790 k1 = 123448 k2 = 227904 k3 = 22790 ans = 1

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

x = 356643 tf_correct = 1 k = 127194229449 l = 12 k2 = 229449 k3 = 22944 k1 = 127194 k2 = 229449 k3 = 22944 ans = 1

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

x = 390313 tf_correct = 1 k = 152344237969 l = 12 k2 = 237969 k3 = 23796 k1 = 152344 k2 = 237969 k3 = 23796 ans = 1

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

x = 461539 tf_correct = 1 k = 213018248521 l = 12 k2 = 248521 k3 = 24852 k1 = 213018 k2 = 248521 k3 = 24852 ans = 1

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

x = 466830 tf_correct = 1 k = 217930248900 l = 12 k2 = 248900 k3 = 24890 k1 = 217930 k2 = 248900 k3 = 24890 ans = 1

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

x = 499500 tf_correct = 1 k = 249500250000 l = 12 k2 = 250000 k3 = 25000 k1 = 249500 k2 = 250000 k3 = 25000 ans = 1

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

x = 500500 tf_correct = 1 k = 250500250000 l = 12 k2 = 250000 k3 = 25000 k1 = 250500 k2 = 250000 k3 = 25000 ans = 1

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

x = 533170 tf_correct = 1 k = 284270248900 l = 12 k2 = 248900 k3 = 24890 k1 = 284270 k2 = 248900 k3 = 24890 ans = 1

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

x = 538461 tf_correct = 1 k = 289940248521 l = 12 k2 = 248521 k3 = 24852 k1 = 289940 k2 = 248521 k3 = 24852 ans = 1

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

x = 609687 tf_correct = 1 k = 371718237969 l = 12 k2 = 237969 k3 = 23796 k1 = 371718 k2 = 237969 k3 = 23796 ans = 1

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

x = 643357 tf_correct = 1 k = 413908229449 l = 12 k2 = 229449 k3 = 22944 k1 = 413908 k2 = 229449 k3 = 22944 ans = 1

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

x = 648648 tf_correct = 1 k = 420744227904 l = 12 k2 = 227904 k3 = 22790 k1 = 420744 k2 = 227904 k3 = 22790 ans = 1

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

x = 670033 tf_correct = 1 k = 448944221089 l = 12 k2 = 221089 k3 = 22108 k1 = 448944 k2 = 221089 k3 = 22108 ans = 1

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

x = 681318 tf_correct = 1 k = 464194217124 l = 12 k2 = 217124 k3 = 21712 k1 = 464194 k2 = 217124 k3 = 21712 ans = 1

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

x = 681319 tf_correct = 0 k = 464195579761 l = 12 k2 = 579761 k3 = 57976 k1 = 464195 k2 = 579761 k3 = 57976 ans = 0

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

x = 681320 tf_correct = 0 k = 464196942400 l = 12 k2 = 942400 k3 = 94240 k1 = 464196 k2 = 942400 k3 = 94240 ans = 0