Cody

Problem 57. Summing Digits within Text

Solution 1866232

Submitted on 5 Jul 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   Fail
str = '4 and 20 blackbirds baked in a pie'; total = 24; assert(isequal(number_sum(str),total))

splitted = 1×8 cell array {'4'} {'and'} {'20'} {'blackbirds'} {'baked'} {'in'} {'a'} {'pie'} array = 1×2 string array " " "4" array = 1×4 string array " " "4" " " "20"

Undefined function 'nansum' for input arguments of type 'double'. Error in number_sum (line 10) total = nansum(str2double(array)) Error in Test1 (line 3) assert(isequal(number_sum(str),total))

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

splitted = 1×8 cell array {'2'} {'4'} {'6'} {'8'} {'who'} {'do'} {'we'} {'appreciate?'} array = 1×2 string array " " "2" array = 1×4 string array " " "2" " " "4" array = 1×6 string array " " "2" " " "4" " " "6" array = 1×8 string array " " "2" " " "4" " " "6" " " "8"

Undefined function 'nansum' for input arguments of type 'double'. Error in number_sum (line 10) total = nansum(str2double(array)) Error in Test2 (line 3) assert(isequal(number_sum(str),total))

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

splitted = 1×9 cell array {'He'} {'worked'} {'at'} {'the'} {'7-11'} {'for'} {'\$10'} {'an'} {'hour'}

Undefined function 'nansum' for input arguments of type 'double'. Error in number_sum (line 10) total = nansum(str2double(array)) Error in Test3 (line 3) assert(isequal(number_sum(str),total))

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

splitted = 1×12 cell array {'that'} {'is'} {'6'} {'of'} {'one'} {'and'} {'a'} {'half'} {'dozen'} {'of'} {'the'} {'other'} array = 1×2 string array " " "6"

Undefined function 'nansum' for input arguments of type 'double'. Error in number_sum (line 10) total = nansum(str2double(array)) Error in Test4 (line 3) assert(isequal(number_sum(str),total))

Community Treasure Hunt

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

Start Hunting!