Cody

# Problem 967. Split a string into chunks of specified length

Solution 2661185

Submitted on 6 Jul 2020
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
s = 'Easy'; b = ones(1,4); y_correct = {'E','a','s','y'}; assert(isequal(break_string(s,b),y_correct))

y = 'E' pos = 2 y = 1×2 cell array {'E'} {'a'} pos = 3 y = 1×2 cell array {1×2 cell} {'s'} pos = 4 y = 1×2 cell array {1×2 cell} {'y'} pos = 5

Assertion failed.

2   Fail
s = 'I seem to be having tremendous difficulty with my lifestyle'; b = [4 1 5 22]; y_correct = {'I se','e','m to ','be having tremendous d'}; assert(isequal(break_string(s,b),y_correct))

y = 'I se' pos = 5 y = 1×2 cell array {'I se'} {'e'} pos = 6 y = 1×2 cell array {1×2 cell} {'m to '} pos = 11 y = 1×2 cell array {1×2 cell} {'be having tremendous d'} pos = 33

Assertion failed.

3   Fail
s = 'The answer is 42'; b = [4 7 3]; y_correct = {'The ','answer ','is '}; assert(isequal(break_string(s,b),y_correct))

y = 'The ' pos = 5 y = 1×2 cell array {'The '} {'answer '} pos = 12 y = 1×2 cell array {1×2 cell} {'is '} pos = 15

Assertion failed.

4   Fail
s = 'Did I do that?'; b = [2 3 3]; y_correct = {'Di','d I',' do'}; assert(isequal(break_string(s,b),y_correct))

y = 'Di' pos = 3 y = 1×2 cell array {'Di'} {'d I'} pos = 6 y = 1×2 cell array {1×2 cell} {' do'} pos = 9

Assertion failed.

5   Fail
s = 'Yes no when?'; b = [2 6 3]; y_correct = {'Ye','s no w','hen'}; assert(isequal(break_string(s,b),y_correct))

y = 'Ye' pos = 3 y = 1×2 cell array {'Ye'} {'s no w'} pos = 9 y = 1×2 cell array {1×2 cell} {'hen'} pos = 12

Assertion failed.

6   Fail
s = 'Hello there'; b = [3 4 4]; y_correct = {'Hel','lo t','here'}; assert(isequal(break_string(s,b),y_correct))

y = 'Hel' pos = 4 y = 1×2 cell array {'Hel'} {'lo t'} pos = 8 y = 1×2 cell array {1×2 cell} {'here'} pos = 12

Assertion failed.

7   Fail
s = 'One is not enough!'; b = [3 1 1]; y_correct = {'One',' ','i'}; assert(isequal(break_string(s,b),y_correct))

y = 'One' pos = 4 y = 1×2 cell array {'One'} {' '} pos = 5 y = 1×2 cell array {1×2 cell} {'i'} pos = 6

Assertion failed.