Cody

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

Solution 1812049

Submitted on 10 May 2019 by Albit
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
s = 'Easy'; b = ones(1,4); y_correct = {'E','a','s','y'}; assert(isequal(break_string(s,b),y_correct))

ende = 1 d = 'E' y = 1×1 cell array {'E'} start = 2 loop = 1 ende = 2 d = 'a' y = 1×2 cell array {'E'} {'a'} start = 3 loop = 2 ende = 3 d = 's' y = 1×3 cell array {'E'} {'a'} {'s'} start = 4 loop = 3 ende = 4 d = 'y' y = 1×4 cell array {'E'} {'a'} {'s'} {'y'} start = 5 loop = 4 y = 1×4 cell array {'E'} {'a'} {'s'} {'y'}

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

ende = 4 d = 'I se' y = 1×1 cell array {'I se'} start = 5 loop = 1 ende = 5 d = 'e' y = 1×2 cell array {'I se'} {'e'} start = 6 loop = 2 ende = 10 d = 'm to ' y = 1×3 cell array {'I se'} {'e'} {'m to '} start = 11 loop = 3 ende = 32 d = 'be having tremendous d' y = 1×4 cell array {'I se'} {'e'} {'m to '} {'be having tremendous d'} start = 33 loop = 4 y = 1×4 cell array {'I se'} {'e'} {'m to '} {'be having tremendous d'}

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

ende = 4 d = 'The ' y = 1×1 cell array {'The '} start = 5 loop = 1 ende = 11 d = 'answer ' y = 1×2 cell array {'The '} {'answer '} start = 12 loop = 2 ende = 14 d = 'is ' y = 1×3 cell array {'The '} {'answer '} {'is '} start = 15 loop = 3 y = 1×3 cell array {'The '} {'answer '} {'is '}

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

ende = 2 d = 'Di' y = 1×1 cell array {'Di'} start = 3 loop = 1 ende = 5 d = 'd I' y = 1×2 cell array {'Di'} {'d I'} start = 6 loop = 2 ende = 8 d = ' do' y = 1×3 cell array {'Di'} {'d I'} {' do'} start = 9 loop = 3 y = 1×3 cell array {'Di'} {'d I'} {' do'}

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

ende = 2 d = 'Ye' y = 1×1 cell array {'Ye'} start = 3 loop = 1 ende = 8 d = 's no w' y = 1×2 cell array {'Ye'} {'s no w'} start = 9 loop = 2 ende = 11 d = 'hen' y = 1×3 cell array {'Ye'} {'s no w'} {'hen'} start = 12 loop = 3 y = 1×3 cell array {'Ye'} {'s no w'} {'hen'}

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

ende = 3 d = 'Hel' y = 1×1 cell array {'Hel'} start = 4 loop = 1 ende = 7 d = 'lo t' y = 1×2 cell array {'Hel'} {'lo t'} start = 8 loop = 2 ende = 11 d = 'here' y = 1×3 cell array {'Hel'} {'lo t'} {'here'} start = 12 loop = 3 y = 1×3 cell array {'Hel'} {'lo t'} {'here'}

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

ende = 3 d = 'One' y = 1×1 cell array {'One'} start = 4 loop = 1 ende = 4 d = ' ' y = 1×2 cell array {'One'} {' '} start = 5 loop = 2 ende = 5 d = 'i' y = 1×3 cell array {'One'} {' '} {'i'} start = 6 loop = 3 y = 1×3 cell array {'One'} {' '} {'i'}