Cody

# Problem 65. Word Counting and Indexing

Solution 2045952

Submitted on 4 Dec 2019 by Asif Newaz
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))

m = 1 n = 2 b = 1×1 cell array {1×3 cell} b = 1×2 cell array {1×3 cell} {1×4 cell} c = 1×7 cell array {'one'} {'two'} {'three'} {'two'} {'one'} {'four'} {'zero'} d = 1×5 cell array {'four'} {'one'} {'three'} {'two'} {'zero'} idx = 1×2 cell array {0×0 double} {[9]}

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

m = 1 n = 1 b = 1×1 cell array {1×3 cell} c = 1×6 cell array {'one'} {'two'} {'three'} {'one'} {'two'} {'three'} d = 1×3 cell array {'one'} {'three'} {'two'} idx = 1×1 cell array {[1]}

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))

m = 2 n = 2 b = 1×1 cell array {1×6 cell} b = 1×2 cell array {1×6 cell} {1×6 cell} b = 2×2 cell array {1×6 cell} {1×6 cell } {1×6 cell} {0×0 double} b = 2×2 cell array {1×6 cell} {1×6 cell} {1×6 cell} {1×9 cell} c = 1×15 cell array Columns 1 through 14 {'this'} {'little'} {'piggy'} {'had'} {'roast'} {'beef'} {'and'} {'this'} {'one'} {'studied'} {'computer'} {'science'} {'at'} {'piggy'} Column 15 {'university'} d = 1×13 cell array {'and'} {'at'} {'beef'} {'computer'} {'had'} {'little'} {'one'} {'piggy'} {'roast'} {'science'} {'studied'} {'this'} {'university'} c = 1×27 cell array Columns 1 through 14 {'this'} {'little'} {'piggy'} {'went'} {'to'} {'market'} {'and'} {'this'} {'little'} {'piggy'} {'stayed'} {'home'} {'this'} {'little'} Columns 15 through 27 {'piggy'} {'had'} {'roast'} {'beef'} {'and'} {'this'} {'one'} {'studied'} {'computer'} {'science'} {'at'} {'piggy'} {'university'} d = 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'} idx = 2×2 cell array {0×0 double} {[1]} {0×0 double} {[1]}