Cody

# Problem 65. Word Counting and Indexing

Solution 1894367

Submitted on 7 Aug 2019 by Todd Snow
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
sl = {'one two three','two one four zero'}; wtc = {'four','one','three','two','zero'}; silc = {[2 4 3],[4 2 1 5]}; [wt,sil] = word_index(sl); assert(isequal(wt,wtc))

str = 'one two three' spaces = 4 8 str = 'two one four zero' spaces = 4 8 13 word_table = 1×5 cell array {'four'} {'one'} {'three'} {'two'} {'zero'} str = 'one two three' spaces = 4 8 str = 'two one four zero' spaces = 4 8 13

2   Pass
sl = {'one two three'}; wtc = {'one','three','two'}; silc = {[1 3 2]}; [wt,sil] = word_index(sl); assert(isequal(wt,wtc))

str = 'one two three' spaces = 4 8 word_table = 1×3 cell array {'one'} {'three'} {'two'} str = 'one two three' spaces = 4 8

3   Pass
sl = {'this little piggy went to market', ... 'and this little piggy stayed home', ... 'this little piggy had roast beef', ... 'and this one studied computer science at piggy university'}; wtc = { ... 'and','at','beef','computer','had','home', ... 'little','market','one','piggy','roast','science', ... 'stayed','studied','this','to','university','went'}; silc = { ... [15 7 10 18 16 8], ... [1 15 7 10 13 6], ... [15 7 10 5 11 3], ... [ 1 15 9 14 4 12 2 10 17]}; [wt,sil] = word_index(sl); assert(isequal(wt,wtc))

str = 'this little piggy went to market' spaces = 5 12 18 23 26 str = 'this little piggy had roast beef' spaces = 5 12 18 22 28 str = 'and this little piggy stayed home' spaces = 4 9 16 22 29 str = 'and this one studied computer science at piggy university' spaces = 4 9 13 21 30 38 41 47 word_table = 1×18 cell array Columns 1 through 14 {'and'} {'at'} {'beef'} {'computer'} {'had'} {'home'} {'little'} {'market'} {'one'} {'piggy'} {'roast'} {'science'} {'stayed'} {'studied'} Columns 15 through 18 {'this'} {'to'} {'university'} {'went'} str = 'this little piggy went to market' spaces = 5 12 18 23 26 str = 'this little piggy had roast beef' spaces = 5 12 18 22 28

### Community Treasure Hunt

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

Start Hunting!