Cody

# Problem 65. Word Counting and Indexing

Solution 247390

Submitted on 21 May 2013 by andrea84
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))

a = [] a = 'one' 'two' 'three' a = 'one' 'two' 'three' 'two' 'one' 'four' 'zero' [Warning: Single input behavior is obsolete and will be removed in a future release of MATLAB. Use C={X} instead.] [> In mat2cell at 53 In word_index at 6 In verifyCode>evaluateCode at 227 In verifyCode at 40 In fevalJSON at 14 In workspacefunc at 7] a = {1x5 cell} a = 'four' 'one' 'three' 'two' 'zero'

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

a = [] a = 'one' 'two' 'three' [Warning: Single input behavior is obsolete and will be removed in a future release of MATLAB. Use C={X} instead.] [> In mat2cell at 53 In word_index at 6 In verifyCode>evaluateCode at 227 In verifyCode at 40 In fevalJSON at 14 In workspacefunc at 7] a = {1x3 cell} a = 'one' 'three' 'two'

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

a = [] a = 'this' 'little' 'piggy' 'went' 'to' 'market' a = Columns 1 through 9 'this' 'little' 'piggy' 'went' 'to' 'market' 'and' 'this' 'little' Columns 10 through 12 'piggy' 'stayed' 'home' a = Columns 1 through 9 'this' 'little' 'piggy' 'went' 'to' 'market' 'and' 'this' 'little' Columns 10 through 18 'piggy' 'stayed' 'home' 'this' 'little' 'piggy' 'had' 'roast' 'beef' a = Columns 1 through 9 'this' 'little' 'piggy' 'went' 'to' 'market' 'and' 'this' 'little' Columns 10 through 18 'piggy' 'stayed' 'home' 'this' 'little' 'piggy' 'had' 'roast' 'beef' Columns 19 through 26 'and' 'this' 'one' 'studied' 'computer' 'science' 'at' 'piggy' Column 27 'university' [Warning: Single input behavior is obsolete and will be removed in a future release of MATLAB. Use C={X} instead.] [> In mat2cell at 53 In word_index at 6 In verifyCode>evaluateCode at 227 In verifyCode at 40 In fevalJSON at 14 In workspacefunc at 7] a = {1x18 cell} a = Columns 1 through 9 'and' 'at' 'beef' 'computer' 'had' 'home' 'little' 'market' 'one' Columns 10 through 17 'piggy' 'roast' 'science' 'stayed' 'studied' 'this' 'to' 'university' Column 18 'went'