Cody

Problem 57. Summing Digits within Text

Solution 3445898

Submitted on 28 Oct 2020 by 元清 谭
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
str = '4 and 20 blackbirds baked in a pie'; total = 24; assert(isequal(number_sum(str),total))

match = 1×31 cell array Columns 1 through 19 {' '} {'a'} {'n'} {'d'} {' '} {' '} {'b'} {'l'} {'a'} {'c'} {'k'} {'b'} {'i'} {'r'} {'d'} {'s'} {' '} {'b'} {'a'} Columns 20 through 31 {'k'} {'e'} {'d'} {' '} {'i'} {'n'} {' '} {'a'} {' '} {'p'} {'i'} {'e'} noMatch = 1×32 cell array Columns 1 through 13 {'4'} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {'20'} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} Columns 14 through 25 {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} Columns 26 through 32 {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char}

2   Pass
str = '2 4 6 8 who do we appreciate?'; total = 20; assert(isequal(number_sum(str),total))

match = 1×25 cell array Columns 1 through 19 {' '} {' '} {' '} {' '} {'w'} {'h'} {'o'} {' '} {'d'} {'o'} {' '} {'w'} {'e'} {' '} {'a'} {'p'} {'p'} {'r'} {'e'} Columns 20 through 25 {'c'} {'i'} {'a'} {'t'} {'e'} {'?'} noMatch = 1×26 cell array Columns 1 through 14 {'2'} {'4'} {'6'} {'8'} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} Columns 15 through 26 {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char}

3   Pass
str = 'He worked at the 7-11 for $10 an hour'; total = 28; assert(isequal(number_sum(str),total))

match = 1×32 cell array Columns 1 through 19 {'H'} {'e'} {' '} {'w'} {'o'} {'r'} {'k'} {'e'} {'d'} {' '} {'a'} {'t'} {' '} {'t'} {'h'} {'e'} {' '} {'-'} {' '} Columns 20 through 32 {'f'} {'o'} {'r'} {' '} {'$'} {' '} {'a'} {'n'} {' '} {'h'} {'o'} {'u'} {'r'} noMatch = 1×33 cell array Columns 1 through 12 {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} Columns 13 through 25 {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {'7'} {'11'} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {'10'} Columns 26 through 33 {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char}

4   Pass
str = 'that is 6 of one and a half dozen of the other'; total = 6; assert(isequal(number_sum(str),total))

match = 1×45 cell array Columns 1 through 19 {'t'} {'h'} {'a'} {'t'} {' '} {'i'} {'s'} {' '} {' '} {'o'} {'f'} {' '} {'o'} {'n'} {'e'} {' '} {'a'} {'n'} {'d'} Columns 20 through 38 {' '} {'a'} {' '} {'h'} {'a'} {'l'} {'f'} {' '} {'d'} {'o'} {'z'} {'e'} {'n'} {' '} {'o'} {'f'} {' '} {'t'} {'h'} Columns 39 through 45 {'e'} {' '} {'o'} {'t'} {'h'} {'e'} {'r'} noMatch = 1×46 cell array Columns 1 through 13 {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {'6'} {0×0 char} {0×0 char} {0×0 char} {0×0 char} Columns 14 through 25 {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} Columns 26 through 37 {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} Columns 38 through 46 {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char} {0×0 char}

Suggested Problems

More from this Author95

Community Treasure Hunt

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

Start Hunting!