Cody

# Problem 1579. How many digits are there?

Solution 2251163

Submitted on 3 May 2020 by Joshua Sonn
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 = 'anbduybefiafn29128r4 ybzw'; y_correct = 6; assert(isequal(digits(x),y_correct))

s = 'anbduybefiafn29128r4ybzw' a = 1×24 uint16 row vector 97 110 98 100 117 121 98 101 102 105 97 102 110 50 57 49 50 56 114 52 121 98 122 119 a = 1×24 uint16 row vector 49 62 50 52 69 73 50 53 54 57 49 54 62 2 9 1 2 8 66 4 73 50 74 71 b = 1×24 uint16 row vector 49 62 50 52 69 73 50 53 54 57 49 54 62 2 9 1 2 8 66 4 73 50 74 71 c = 1×6 uint16 row vector 2 9 1 2 8 4 n = 6

2   Pass
x = 'anuk32y7rhcscbniv82 bv7hf bA^#2tR*Gqvg'; y_correct = 7; assert(isequal(digits(x),y_correct))

s = 'anuk32y7rhcscbniv82bv7hfbA2tRGqvg' a = 1×33 uint16 row vector Columns 1 through 29 97 110 117 107 51 50 121 55 114 104 99 115 99 98 110 105 118 56 50 98 118 55 104 102 98 65 50 116 82 Columns 30 through 33 71 113 118 103 a = 1×33 uint16 row vector 49 62 69 59 3 2 73 7 66 56 51 67 51 50 62 57 70 8 2 50 70 7 56 54 50 17 2 68 34 23 65 70 55 b = 1×33 uint16 row vector 49 62 69 59 3 2 73 7 66 56 51 67 51 50 62 57 70 8 2 50 70 7 56 54 50 17 2 68 34 23 65 70 55 c = 1×7 uint16 row vector 3 2 7 8 2 7 2 n = 7

3   Pass
x = '1234567890'; y_correct = 10; assert(isequal(digits(x),y_correct))

s = '1234567890' a = 1×10 uint16 row vector 49 50 51 52 53 54 55 56 57 48 a = 1×10 uint16 row vector 1 2 3 4 5 6 7 8 9 0 b = 1×10 uint16 row vector 1 2 3 4 5 6 7 8 9 0 c = 1×10 uint16 row vector 1 2 3 4 5 6 7 8 9 0 n = 10

4   Pass
x = 'a1b2c3d4e5f6g7h8i9'; y_correct = 9; assert(isequal(digits(x),y_correct))

s = 'a1b2c3d4e5f6g7h8i9' a = 1×18 uint16 row vector 97 49 98 50 99 51 100 52 101 53 102 54 103 55 104 56 105 57 a = 1×18 uint16 row vector 49 1 50 2 51 3 52 4 53 5 54 6 55 7 56 8 57 9 b = 1×18 uint16 row vector 49 1 50 2 51 3 52 4 53 5 54 6 55 7 56 8 57 9 c = 1×9 uint16 row vector 1 2 3 4 5 6 7 8 9 n = 9

5   Pass
x = 's;dfj98798324k kds \$:J(%*n 34 ;ljkasr87 34w ;lkj3 aoij5l;j;q 35'; y_correct = 18; assert(isequal(digits(x),y_correct))

s = 's;dfj98798324kkds:Jn34;ljkasr8734w;lkj3aoij5l;j;q35' a = 1×51 uint16 row vector Columns 1 through 29 115 59 100 102 106 57 56 55 57 56 51 50 52 107 107 100 115 58 74 110 51 52 59 108 106 107 97 115 114 Columns 30 through 51 56 55 51 52 119 59 108 107 106 51 97 111 105 106 53 108 59 106 59 113 51 53 a = 1×51 uint16 row vector Columns 1 through 35 67 11 52 54 58 9 8 7 9 8 3 2 4 59 59 52 67 10 26 62 3 4 11 60 58 59 49 67 66 8 7 3 4 71 11 Columns 36 through 51 60 59 58 3 49 63 57 58 5 60 11 58 11 65 3 5 b = 1×51 uint16 row vector Columns 1 through 35 67 11 52 54 58 9 8 7 9 8 3 2 4 59 59 52 67 10 26 62 3 4 11 60 58 59 49 67 66 8 7 3 4 71 11 Columns 36 through 51 60 59 58 3 49 63 57 58 5 60 11 58 11 65 3 5 c = 1×18 uint16 row vector 9 8 7 9 8 3 2 4 3 4 8 7 3 4 3 5 3 5 n = 18

6   Pass
x = num2str(1:100); y_correct = 192; assert(isequal(digits(x),y_correct))

s = '123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100' a = 1×192 uint16 row vector Columns 1 through 35 49 50 51 52 53 54 55 56 57 49 48 49 49 49 50 49 51 49 52 49 53 49 54 49 55 49 56 49 57 50 48 50 49 50 50 Columns 36 through 70 50 51 50 52 50 53 50 54 50 55 50 56 50 57 51 48 51 49 51 50 51 51 51 52 51 53 51 54 51 55 51 56 51 57 52 Columns 71 through 105 48 52 49 52 50 52 51 52 52 52 53 52 54 52 55 52 56 52 57 53 48 53 49 53 50 53 51 53 52 53 53 53 54 53 55 Columns 106 through 140 53 56 53 57 54 48 54 49 54 50 54 51 54 52 54 53 54 54 54 55 54 56 54 57 55 48 55 49 55 50 55 51 55 52 55 Columns 141 through 175 53 55 54 55 55 55 56 55 57 56 48 56 49 56 50 56 51 56 52 56 53 56 54 56 55 56 56 56 57 57 48 57 49 57 50 Columns 176 through 192 57 51 57 52 57 53 57 54 57 55 57 56 57 57 49 48 48 a = 1×192 uint16 row vector Columns 1 through 44 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 Columns 45 through 88 7 2 8 2 9 3 0 3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3 9 4 0 4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4 Columns 89 through 132 9 5 0 5 1 5 2 5 3 5 4 5 5 5 6 5 7 5 8 5 9 6 0 6 1 6 2 6 3 6 4 6 5 6 6 6 7 6 8 6 9 7 0 7 Columns 133 through 176 1 7 2 7 3 7 4 7 5 7 6 7 7 7 8 7 9 8 0 8 1 8 2 8 3 8 4 8 5 8 6 8 7 8 8 8 9 9 0 9 1 9 2 9 Columns 177 through 192 3 9 4 9 5 9 6 9 7 9 8 9 9 1 0 0 b = 1×192 uint16 row vector Columns 1 through 44 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 Columns 45 through 88 7 2 8 2 9 3 0 3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3 9 4 0 4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4 Columns 89 through 132 9 5 0 5 1 5 2 5 3 5 4 5 5 5 6 5 7 5 8 5 9 6 0 6 1 6 2 6 3 6 4 6 5 6 6 6 7 6 8 6 9 7 0 7 Columns 133 through 176 1 7 2 7 3 7 4 7 5 7 6 7 7 7 8 7 9 8 0 8 1 8 2 8 3 8 4 8 5 8 6 8 7 8 8 8 9 9 0 9 1 9 2 9 Columns 177 through 192 3 9 4 9 5 9 6 9 7 9 8 9 9 1 0 0 c = 1×192 uint16 row vector Columns 1 through 44 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 Columns 45 through 88 7 2 8 2 9 3 0 3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3 9 4 0 4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4 Columns 89 through 132 9 5 0 5 1 5 2 5 3 5 4 5 5 5 6 5 7 5 8 5 9 6 0 6 1 6 2 6 3 6 4 6 5 6 6 6 7 6 8 6 9 7 0 7 Columns 133 through 176 1 7 2 7 3 7 4 7 5 7 6 7 7 7 8 7 9 8 0 8 1 8 2 8 3 8 4 8 5 8 6 8 7 8 8 8 9 9 0 9 1 9 2 9 Columns 177 through 192 3 9 4 9 5 9 6 9 7 9 8 9 9 1 0 0 n = 192

7   Pass
x = 'The answer is 42.'; y_correct = 2; assert(isequal(digits(x),y_correct))

s = 'Theansweris42' a = 1×13 uint16 row vector 84 104 101 97 110 115 119 101 114 105 115 52 50 a = 1×13 uint16 row vector 36 56 53 49 62 67 71 53 66 57 67 4 2 b = 1×13 uint16 row vector 36 56 53 49 62 67 71 53 66 57 67 4 2 c = 1×2 uint16 row vector 4 2 n = 2

### Community Treasure Hunt

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

Start Hunting!