Cody

# Problem 166. Kaprekar numbers

Solution 1909988

Submitted on 23 Aug 2019
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))

s = '16' n = 2 x2 = 256 s2 = '256' n2 = 3 DX = 56 SX = 2 tf = logical 0

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

s = '704' n = 3 x2 = 495616 s2 = '495616' n2 = 6 DX = 616 SX = 49 tf = logical 0

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

x = 9 tf_correct = logical 1 s = '9' n = 1 x2 = 81 s2 = '81' n2 = 2 DX = 1 SX = NaN tf = logical 0

Assertion failed.

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

x = 45 tf_correct = logical 1 s = '45' n = 2 x2 = 2025 s2 = '2025' n2 = 4 DX = 25 SX = 2 tf = logical 0

Assertion failed.

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

x = 55 tf_correct = logical 1 s = '55' n = 2 x2 = 3025 s2 = '3025' n2 = 4 DX = 25 SX = 3 tf = logical 0

Assertion failed.

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

x = 99 tf_correct = logical 1 s = '99' n = 2 x2 = 9801 s2 = '9801' n2 = 4 DX = 1 SX = 9 tf = logical 0

Assertion failed.

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

x = 297 tf_correct = logical 1 s = '297' n = 3 x2 = 88209 s2 = '88209' n2 = 5 DX = 209 SX = 88 tf = logical 1

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

x = 703 tf_correct = logical 1 s = '703' n = 3 x2 = 494209 s2 = '494209' n2 = 6 DX = 209 SX = 49 tf = logical 0

Assertion failed.

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

x = 999 tf_correct = logical 1 s = '999' n = 3 x2 = 998001 s2 = '998001' n2 = 6 DX = 1 SX = 99 tf = logical 0

Assertion failed.

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

x = 2223 tf_correct = logical 1 s = '2223' n = 4 x2 = 4941729 s2 = '4941729' n2 = 7 DX = 1729 SX = 494 tf = logical 1

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

x = 2728 tf_correct = logical 1 s = '2728' n = 4 x2 = 7441984 s2 = '7441984' n2 = 7 DX = 1984 SX = 744 tf = logical 1

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

x = 4950 tf_correct = logical 1 s = '4950' n = 4 x2 = 24502500 s2 = '24502500' n2 = 8 DX = 2500 SX = 245 tf = logical 0

Assertion failed.

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

x = 5050 tf_correct = logical 1 s = '5050' n = 4 x2 = 25502500 s2 = '25502500' n2 = 8 DX = 2500 SX = 255 tf = logical 0

Assertion failed.

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

x = 7272 tf_correct = logical 1 s = '7272' n = 4 x2 = 52881984 s2 = '52881984' n2 = 8 DX = 1984 SX = 528 tf = logical 0

Assertion failed.

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

x = 7777 tf_correct = logical 1 s = '7777' n = 4 x2 = 60481729 s2 = '60481729' n2 = 8 DX = 1729 SX = 604 tf = logical 0

Assertion failed.

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

x = 9999 tf_correct = logical 1 s = '9999' n = 4 x2 = 99980001 s2 = '99980001' n2 = 8 DX = 1 SX = 999 tf = logical 0

Assertion failed.

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

x = 17344 tf_correct = logical 1 s = '17344' n = 5 x2 = 300814336 s2 = '300814336' n2 = 9 DX = 14336 SX = 3008 tf = logical 1

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

x = 22222 tf_correct = logical 1 s = '22222' n = 5 x2 = 493817284 s2 = '493817284' n2 = 9 DX = 17284 SX = 4938 tf = logical 1

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

x = 77778 tf_correct = logical 1 s = '77778' n = 5 x2 = 6.0494e+09 s2 = '6049417284' n2 = 10 DX = 17284 SX = 6049 tf = logical 0

Assertion failed.

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

x = 82656 tf_correct = logical 1 s = '82656' n = 5 x2 = 6.8320e+09 s2 = '6832014336' n2 = 10 DX = 14336 SX = 6832 tf = logical 0

Assertion failed.

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

x = 95121 tf_correct = logical 1 s = '95121' n = 5 x2 = 9.0480e+09 s2 = '9048004641' n2 = 10 DX = 4641 SX = 9048 tf = logical 0

Assertion failed.

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

x = 99999 tf_correct = logical 1 s = '99999' n = 5 x2 = 9.9998e+09 s2 = '9999800001' n2 = 10 DX = 1 SX = 9999 tf = logical 0

Assertion failed.

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

x = 142857 tf_correct = logical 1 s = '142857' n = 6 x2 = 2.0408e+10 s2 = '20408122449' n2 = 11 DX = 122449 SX = 20408 tf = logical 1

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

x = 148149 tf_correct = logical 1 s = '148149' n = 6 x2 = 2.1948e+10 s2 = '21948126201' n2 = 11 DX = 126201 SX = 21948 tf = logical 1

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

x = 181819 tf_correct = logical 1 s = '181819' n = 6 x2 = 3.3058e+10 s2 = '33058148761' n2 = 11 DX = 148761 SX = 33058 tf = logical 1

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

x = 187110 tf_correct = logical 1 s = '187110' n = 6 x2 = 3.5010e+10 s2 = '35010152100' n2 = 11 DX = 152100 SX = 35010 tf = logical 1

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

x = 208495 tf_correct = logical 1 s = '208495' n = 6 x2 = 4.3470e+10 s2 = '43470165025' n2 = 11 DX = 165025 SX = 43470 tf = logical 1

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

x = 318682 tf_correct = logical 1 s = '318682' n = 6 x2 = 1.0156e+11 s2 = '101558217124' n2 = 12 DX = 217124 SX = 10155 tf = logical 0

Assertion failed.

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

x = 329967 tf_correct = logical 1 s = '329967' n = 6 x2 = 1.0888e+11 s2 = '108878221089' n2 = 12 DX = 221089 SX = 10887 tf = logical 0

Assertion failed.

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

x = 351352 tf_correct = logical 1 s = '351352' n = 6 x2 = 1.2345e+11 s2 = '123448227904' n2 = 12 DX = 227904 SX = 12344 tf = logical 0

Assertion failed.

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

x = 356643 tf_correct = logical 1 s = '356643' n = 6 x2 = 1.2719e+11 s2 = '127194229449' n2 = 12 DX = 229449 SX = 12719 tf = logical 0

Assertion failed.

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

x = 390313 tf_correct = logical 1 s = '390313' n = 6 x2 = 1.5234e+11 s2 = '152344237969' n2 = 12 DX = 237969 SX = 15234 tf = logical 0

Assertion failed.

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

x = 461539 tf_correct = logical 1 s = '461539' n = 6 x2 = 2.1302e+11 s2 = '213018248521' n2 = 12 DX = 248521 SX = 21301 tf = logical 0

Assertion failed.

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

x = 466830 tf_correct = logical 1 s = '466830' n = 6 x2 = 2.1793e+11 s2 = '217930248900' n2 = 12 DX = 248900 SX = 21793 tf = logical 0

Assertion failed.

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

x = 499500 tf_correct = logical 1 s = '499500' n = 6 x2 = 2.4950e+11 s2 = '249500250000' n2 = 12 DX = 250000 SX = 24950 tf = logical 0

Assertion failed.

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

x = 500500 tf_correct = logical 1 s = '500500' n = 6 x2 = 2.5050e+11 s2 = '250500250000' n2 = 12 DX = 250000 SX = 25050 tf = logical 0

Assertion failed.

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

x = 533170 tf_correct = logical 1 s = '533170' n = 6 x2 = 2.8427e+11 s2 = '284270248900' n2 = 12 DX = 248900 SX = 28427 tf = logical 0

Assertion failed.

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

x = 538461 tf_correct = logical 1 s = '538461' n = 6 x2 = 2.8994e+11 s2 = '289940248521' n2 = 12 DX = 248521 SX = 28994 tf = logical 0

Assertion failed.

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

x = 609687 tf_correct = logical 1 s = '609687' n = 6 x2 = 3.7172e+11 s2 = '371718237969' n2 = 12 DX = 237969 SX = 37171 tf = logical 0

Assertion failed.

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

x = 643357 tf_correct = logical 1 s = '643357' n = 6 x2 = 4.1391e+11 s2 = '413908229449' n2 = 12 DX = 229449 SX = 41390 tf = logical 0

Assertion failed.

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

x = 648648 tf_correct = logical 1 s = '648648' n = 6 x2 = 4.2074e+11 s2 = '420744227904' n2 = 12 DX = 227904 SX = 42074 tf = logical 0

Assertion failed.

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

x = 670033 tf_correct = logical 1 s = '670033' n = 6 x2 = 4.4894e+11 s2 = '448944221089' n2 = 12 DX = 221089 SX = 44894 tf = logical 0

Assertion failed.

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

x = 681318 tf_correct = logical 1 s = '681318' n = 6 x2 = 4.6419e+11 s2 = '464194217124' n2 = 12 DX = 217124 SX = 46419 tf = logical 0

Assertion failed.

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

x = 681319 tf_correct = logical 0 s = '681319' n = 6 x2 = 4.6420e+11 s2 = '464195579761' n2 = 12 DX = 579761 SX = 46419 tf = logical 0

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

x = 681320 tf_correct = logical 0 s = '681320' n = 6 x2 = 4.6420e+11 s2 = '464196942400' n2 = 12 DX = 942400 SX = 46419 tf = logical 0