Cody

Problem 57. Summing Digits within Text

Solution 2024193

Submitted on 16 Nov 2019 by Doan Quang Manh
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))

b = Columns 1 through 29 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 Columns 30 through 34 30 31 32 33 34 a = 1 7 8 c = Columns 1 through 29 2 3 4 5 6 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 Columns 30 through 31 33 34 str = '4 20 ' total = 24

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

b = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 a = 1 3 5 7 c = 2 4 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 str = '2 4 6 8 ' total = 20

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

b = Columns 1 through 29 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 Columns 30 through 37 30 31 32 33 34 35 36 37 a = 18 20 21 28 29 c = Columns 1 through 29 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 19 22 23 24 25 26 27 30 31 32 33 34 Columns 30 through 32 35 36 37 str = ' 7 11 10 ' total = 28

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

b = Columns 1 through 29 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 Columns 30 through 46 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 a = 9 c = Columns 1 through 29 1 2 3 4 5 6 7 8 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Columns 30 through 45 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 str = ' 6 ' total = 6

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!