Cody

# Problem 1579. How many digits are there?

Solution 3857808

Submitted on 26 Nov 2020 by Akrem Hadji
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))

j = '0' s = 0 j = '1' s = 1 j = '2' s = 3 j = '3' s = 3 j = '4' s = 4 j = '5' s = 4 j = '6' s = 4 j = '7' s = 4 j = '8' s = 5 j = '9' s = 6

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

j = '0' s = 0 j = '1' s = 0 j = '2' s = 3 j = '3' s = 4 j = '4' s = 4 j = '5' s = 4 j = '6' s = 4 j = '7' s = 6 j = '8' s = 7 j = '9' s = 7

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

j = '0' s = 1 j = '1' s = 2 j = '2' s = 3 j = '3' s = 4 j = '4' s = 5 j = '5' s = 6 j = '6' s = 7 j = '7' s = 8 j = '8' s = 9 j = '9' s = 10

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

j = '0' s = 0 j = '1' s = 1 j = '2' s = 2 j = '3' s = 3 j = '4' s = 4 j = '5' s = 5 j = '6' s = 6 j = '7' s = 7 j = '8' s = 8 j = '9' s = 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))

j = '0' s = 0 j = '1' s = 0 j = '2' s = 1 j = '3' s = 6 j = '4' s = 9 j = '5' s = 11 j = '6' s = 11 j = '7' s = 13 j = '8' s = 16 j = '9' s = 18

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

j = '0' s = 11 j = '1' s = 32 j = '2' s = 52 j = '3' s = 72 j = '4' s = 92 j = '5' s = 112 j = '6' s = 132 j = '7' s = 152 j = '8' s = 172 j = '9' s = 192

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

j = '0' s = 0 j = '1' s = 0 j = '2' s = 1 j = '3' s = 1 j = '4' s = 2 j = '5' s = 2 j = '6' s = 2 j = '7' s = 2 j = '8' s = 2 j = '9' s = 2

### Community Treasure Hunt

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

Start Hunting!