Cody

# Problem 42482. Repeat string n times

Solution 1609171

Submitted on 14 Aug 2018 by Srishti Saha
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
filetext = fileread('rep_str.m'); assert(isempty(strfind(filetext, 'for'))) assert(isempty(strfind(filetext, 'while')))

2   Pass
x = 'string_'; num1 = 6; n = 3; y_correct = {'string_6' 'string_7' 'string_8'}; assert(isequal(rep_str(x,num1,n),y_correct))

nbrs = 6 7 8 nbrs = 1×3 string array "6" "7" "8" x = 'string_' y = 1×3 string array "string_6" "string_7" "string_8" y = 3×1 string array "string_6" "string_7" "string_8" y = 3×1 cell array {'string_6'} {'string_7'} {'string_8'}

3   Pass
x = 'stringX_'; num1 = 2; n = 1; y_correct = {'stringX_2'}; assert(isequal(rep_str(x,num1,n),y_correct))

nbrs = 2 nbrs = "2" x = 'stringX_' y = "stringX_2" y = "stringX_2" y = 1×1 cell array {'stringX_2'}

4   Pass
x = 'stringA_'; num1 = 8; n = 4; y_correct = {'stringA_8' 'stringA_9' 'stringA_10' 'stringA_11'}; assert(isequal(rep_str(x,num1,n),y_correct))

nbrs = 8 9 10 11 nbrs = 1×4 string array "8" "9" "10" "11" x = 'stringA_' y = 1×4 string array "stringA_8" "stringA_9" "stringA_10" "stringA_11" y = 4×1 string array "stringA_8" "stringA_9" "stringA_10" "stringA_11" y = 4×1 cell array {'stringA_8' } {'stringA_9' } {'stringA_10'} {'stringA_11'}

5   Pass
x = 'strM_'; num1 = 0; n = 5; y_correct = {'strM_0' 'strM_1' 'strM_2' 'strM_3' 'strM_4'}; assert(isequal(rep_str(x,num1,n),y_correct))

nbrs = 0 1 2 3 4 nbrs = 1×5 string array "0" "1" "2" "3" "4" x = 'strM_' y = 1×5 string array "strM_0" "strM_1" "strM_2" "strM_3" "strM_4" y = 5×1 string array "strM_0" "strM_1" "strM_2" "strM_3" "strM_4" y = 5×1 cell array {'strM_0'} {'strM_1'} {'strM_2'} {'strM_3'} {'strM_4'}