Cody

Problem 1579. How many digits are there?

Solution 2251174

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))

B = 1×7 uint16 row vector 50 57 49 50 56 32 52 n = 6

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

B = 1×11 uint16 row vector 51 50 32 55 32 56 50 32 55 32 50 n = 7

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

B = 1×10 uint16 row vector 49 50 51 52 53 54 55 56 57 48 n = 10

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

B = 1×17 uint16 row vector 49 32 50 32 51 32 52 32 53 32 54 32 55 32 56 32 57 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))

B = 1×24 uint16 row vector 57 56 55 57 56 51 50 52 32 51 52 32 56 55 32 51 52 32 51 32 53 32 51 53 n = 18

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

B = 1×291 uint16 row vector Columns 1 through 35 49 32 50 32 51 32 52 32 53 32 54 32 55 32 56 32 57 32 49 48 32 49 49 32 49 50 32 49 51 32 49 52 32 49 53 Columns 36 through 70 32 49 54 32 49 55 32 49 56 32 49 57 32 50 48 32 50 49 32 50 50 32 50 51 32 50 52 32 50 53 32 50 54 32 50 Columns 71 through 105 55 32 50 56 32 50 57 32 51 48 32 51 49 32 51 50 32 51 51 32 51 52 32 51 53 32 51 54 32 51 55 32 51 56 32 Columns 106 through 140 51 57 32 52 48 32 52 49 32 52 50 32 52 51 32 52 52 32 52 53 32 52 54 32 52 55 32 52 56 32 52 57 32 53 48 Columns 141 through 175 32 53 49 32 53 50 32 53 51 32 53 52 32 53 53 32 53 54 32 53 55 32 53 56 32 53 57 32 54 48 32 54 49 32 54 Columns 176 through 210 50 32 54 51 32 54 52 32 54 53 32 54 54 32 54 55 32 54 56 32 54 57 32 55 48 32 55 49 32 55 50 32 55 51 32 Columns 211 through 245 55 52 32 55 53 32 55 54 32 55 55 32 55 56 32 55 57 32 56 48 32 56 49 32 56 50 32 56 51 32 56 52 32 56 53 Columns 246 through 280 32 56 54 32 56 55 32 56 56 32 56 57 32 57 48 32 57 49 32 57 50 32 57 51 32 57 52 32 57 53 32 57 54 32 57 Columns 281 through 291 55 32 57 56 32 57 57 32 49 48 48 n = 192

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

B = 1×2 uint16 row vector 52 50 n = 2

Suggested Problems

More from this Author9

Community Treasure Hunt

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

Start Hunting!