Cody

Solution 1986203

Submitted on 22 Oct 2019 at 15:38
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
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_list = 'one two three two one four zero' exp = '\s*' match = 1×7 cell array {'one'} {'two'} {'three'} {'two'} {'one'} {'four'} {'zero'} word_table = 1×7 cell array {'one'} {'two'} {'three'} {'two'} {'one'} {'four'} {'zero'} match = 1×7 string array "one" "two" "three" "two" "one" "four" "zero" s2 = 1×5 string array "four" "one" "three" "two" "zero" s2 = 1×5 string array "four" "one" "three" "two" "zero" fnd = 2 str_index_list = 1×1 cell array {[2]} fnd = 4 str_index_list = 1×2 cell array {[2]} {[4]} fnd = 3 str_index_list = 1×3 cell array {[2]} {[4]} {[3]} fnd = 4 str_index_list = 1×4 cell array {[2]} {[4]} {[3]} {[4]} fnd = 2 str_index_list = 1×5 cell array {[2]} {[4]} {[3]} {[4]} {[2]} fnd = 1 str_index_list = 1×6 cell array {[2]} {[4]} {[3]} {[4]} {[2]} {[1]} fnd = 5 str_index_list = 1×7 cell array {[2]} {[4]} {[3]} {[4]} {[2]} {[1]} {[5]}

Assertion failed.

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

str_list = 'one two three' exp = '\s*' match = 1×3 cell array {'one'} {'two'} {'three'} word_table = 1×3 cell array {'one'} {'two'} {'three'} match = 1×3 string array "one" "two" "three" s2 = 1×3 string array "one" "three" "two" s2 = 1×3 string array "one" "three" "two" fnd = 1 str_index_list = 1×1 cell array {[1]} fnd = 3 str_index_list = 1×2 cell array {[1]} {[3]} fnd = 2 str_index_list = 1×3 cell array {[1]} {[3]} {[2]}

Assertion failed.

3   Fail
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_list = 'this little piggy went to market this little piggy had roast beef and this little piggy stayed home and this one studied computer science at piggy university' exp = '\s*' match = 1×27 cell array Columns 1 through 14 {'this'} {'little'} {'piggy'} {'went'} {'to'} {'market'} {'this'} {'little'} {'piggy'} {'had'} {'roast'} {'beef'} {'and'} {'this'} Columns 15 through 27 {'little'} {'piggy'} {'stayed'} {'home'} {'and'} {'this'} {'one'} {'studied'} {'computer'} {'science'} {'at'} {'piggy'} {'university'} word_table = 1×27 cell array Columns 1 through 14 {'this'} {'little'} {'piggy'} {'went'} {'to'} {'market'} {'this'} {'little'} {'piggy'} {'had'} {'roast'} {'beef'} {'and'} {'this'} Columns 15 through 27 {'little'} {'piggy'} {'stayed'} {'home'} {'and'} {'this'} {'one'} {'studied'} {'computer'} {'science'} {'at'} {'piggy'} {'university'} match = 1×27 string array Columns 1 through 17 "this" "little" "piggy" "went" "to" "market" "this" "little" "piggy" "had" "roast" "beef" "and" "this" "little" "piggy" "stayed" Columns 18 through 27 "home" "and" "this" "one" "studied" "computer" "science" "at" "piggy" "university" s2 = 1×18 string array Columns 1 through 16 "and" "at" "beef" "computer" "had" "home" "little" "market" "one" "piggy" "roast" "science" "stayed" "studied" "this" "to" Columns 17 through 18 "university" "went" s2 = 1×18 string array Columns 1 through 16 "and" "at" "beef" "computer" "had" "home" "little" "market" "one" "piggy" "roast" "science" "stayed" "studied" "this" "to" Columns 17 through 18 "university" "went" fnd = 15 str_index_list = 1×1 cell array {[15]} fnd = 7 str_index_list = 1×2 cell array {[15]} {[7]} fnd = 10 str_index_list = 1×3 cell array {[15]} {[7]} {[10]} fnd = 18 str_index_list = 1×4 cell array {[15]} {[7]} {[10]} {[18]} fnd = 16 str_index_list = 1×5 cell array {[15]} {[7]} {[10]} {[18]} {[16]} fnd = 8 str_index_list = 1×6 cell array {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} fnd = 15 str_index_list = 1×7 cell array {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} fnd = 7 str_index_list = 1×8 cell array {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} {[7]} fnd = 10 str_index_list = 1×9 cell array {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} {[7]} {[10]} fnd = 5 str_index_list = 1×10 cell array {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} {[7]} {[10]} {[5]} fnd = 11 str_index_list = 1×11 cell array {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} {[7]} {[10]} {[5]} {[11]} fnd = 3 str_index_list = 1×12 cell array {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} {[7]} {[10]} {[5]} {[11]} {[3]} fnd = 1 str_index_list = 1×13 cell array {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} {[7]} {[10]} {[5]} {[11]} {[3]} {[1]} fnd = 15 str_index_list = 1×14 cell array {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} {[7]} {[10]} {[5]} {[11]} {[3]} {[1]} {[15]} fnd = 7 str_index_list = 1×15 cell array {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} {[7]} {[10]} {[5]} {[11]} {[3]} {[1]} {[15]} {[7]} fnd = 10 str_index_list = 1×16 cell array {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} {[7]} {[10]} {[5]} {[11]} {[3]} {[1]} {[15]} {[7]} {[10]} fnd = 13 str_index_list = 1×17 cell array {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} {[7]} {[10]} {[5]} {[11]} {[3]} {[1]} {[15]} {[7]} {[10]} {[13]} fnd = 6 str_index_list = 1×18 cell array {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} {[7]} {[10]} {[5]} {[11]} {[3]} {[1]} {[15]} {[7]} {[10]} {[13]} {[6]} fnd = 1 str_index_list = 1×19 cell array {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} {[7]} {[10]} {[5]} {[11]} {[3]} {[1]} {[15]} {[7]} {[10]} {[13]} {[6]} {[1]} fnd = 15 str_index_list = 1×20 cell array Columns 1 through 19 {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} {[7]} {[10]} {[5]} {[11]} {[3]} {[1]} {[15]} {[7]} {[10]} {[13]} {[6]} {[1]} Column 20 {[15]} fnd = 9 str_index_list = 1×21 cell array Columns 1 through 19 {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} {[7]} {[10]} {[5]} {[11]} {[3]} {[1]} {[15]} {[7]} {[10]} {[13]} {[6]} {[1]} Columns 20 through 21 {[15]} {[9]} fnd = 14 str_index_list = 1×22 cell array Columns 1 through 19 {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} {[7]} {[10]} {[5]} {[11]} {[3]} {[1]} {[15]} {[7]} {[10]} {[13]} {[6]} {[1]} Columns 20 through 22 {[15]} {[9]} {[14]} fnd = 4 str_index_list = 1×23 cell array Columns 1 through 19 {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} {[7]} {[10]} {[5]} {[11]} {[3]} {[1]} {[15]} {[7]} {[10]} {[13]} {[6]} {[1]} Columns 20 through 23 {[15]} {[9]} {[14]} {[4]} fnd = 12 str_index_list = 1×24 cell array Columns 1 through 19 {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} {[7]} {[10]} {[5]} {[11]} {[3]} {[1]} {[15]} {[7]} {[10]} {[13]} {[6]} {[1]} Columns 20 through 24 {[15]} {[9]} {[14]} {[4]} {[12]} fnd = 2 str_index_list = 1×25 cell array Columns 1 through 19 {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} {[7]} {[10]} {[5]} {[11]} {[3]} {[1]} {[15]} {[7]} {[10]} {[13]} {[6]} {[1]} Columns 20 through 25 {[15]} {[9]} {[14]} {[4]} {[12]} {[2]} fnd = 10 str_index_list = 1×26 cell array Columns 1 through 19 {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} {[7]} {[10]} {[5]} {[11]} {[3]} {[1]} {[15]} {[7]} {[10]} {[13]} {[6]} {[1]} Columns 20 through 26 {[15]} {[9]} {[14]} {[4]} {[12]} {[2]} {[10]} fnd = 17 str_index_list = 1×27 cell array Columns 1 through 19 {[15]} {[7]} {[10]} {[18]} {[16]} {[8]} {[15]} {[7]} {[10]} {[5]} {[11]} {[3]} {[1]} {[15]} {[7]} {[10]} {[13]} {[6]} {[1]} Columns 20 through 27 {[15]} {[9]} {[14]} {[4]} {[12]} {[2]} {[10]} {[17]}

Assertion failed.