Cody

# Problem 1853. Enlarge array

Solution 1020758

Submitted on 18 Oct 2016 by Jakub Mrowka
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
A = randi(100); sz = [randi(100) 1]; B_correct = repmat(A,sz); assert(isequal(enlarge(A,sz),B_correct))

a1 = 1 a2 = 1 B = 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85

2   Pass
A = randi(1000); sz = [1 randi(1000)]; B_correct = repmat(A,sz); assert(isequal(enlarge(A,sz),B_correct))

a1 = 1 a2 = 1 B = Columns 1 through 16 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 Columns 17 through 32 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 Columns 33 through 48 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 Columns 49 through 64 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 Columns 65 through 80 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 Columns 81 through 96 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 Columns 97 through 112 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 Columns 113 through 128 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 Columns 129 through 144 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 Columns 145 through 160 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 Columns 161 through 176 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 Columns 177 through 192 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 636 Columns 193 through 202 636 636 636 636 636 636 636 636 636 636

3   Pass
A = eye(3); sz = [2 4]; B_correct = [1 1 1 1 0 0 0 0 0 0 0 0; 1 1 1 1 0 0 0 0 0 0 0 0; 0 0 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1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 B = 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 B = 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1

4   Pass
A = magic(4); sz = [3 3]; B_correct = [16 16 16 2 2 2 3 3 3 13 13 13; 16 16 16 2 2 2 3 3 3 13 13 13; 16 16 16 2 2 2 3 3 3 13 13 13; 5 5 5 11 11 11 10 10 10 8 8 8; 5 5 5 11 11 11 10 10 10 8 8 8; 5 5 5 11 11 11 10 10 10 8 8 8; 9 9 9 7 7 7 6 6 6 12 12 12; 9 9 9 7 7 7 6 6 6 12 12 12; 9 9 9 7 7 7 6 6 6 12 12 12; 4 4 4 14 14 14 15 15 15 1 1 1; 4 4 4 14 14 14 15 15 15 1 1 1; 4 4 4 14 14 14 15 15 15 1 1 1]; assert(isequal(enlarge(A,sz),B_correct))

a1 = 4 a2 = 4 B = 16 16 16 0 0 0 0 0 0 0 0 0 16 16 16 0 0 0 0 0 0 0 0 0 16 16 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 B = 16 16 16 2 2 2 3 3 3 13 13 13 16 16 16 2 2 2 3 3 3 13 13 13 16 16 16 2 2 2 3 3 3 13 13 13 5 5 5 11 11 11 10 10 10 8 8 8 5 5 5 11 11 11 10 10 10 8 8 8 5 5 5 11 11 11 10 10 10 8 8 8 9 9 9 0 0 0 0 0 0 0 0 0 9 9 9 0 0 0 0 0 0 0 0 0 9 9 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 B = 16 16 16 2 2 2 3 3 3 13 13 13 16 16 16 2 2 2 3 3 3 13 13 13 16 16 16 2 2 2 3 3 3 13 13 13 5 5 5 11 11 11 10 10 10 8 8 8 5 5 5 11 11 11 10 10 10 8 8 8 5 5 5 11 11 11 10 10 10 8 8 8 9 9 9 7 7 7 0 0 0 0 0 0 9 9 9 7 7 7 0 0 0 0 0 0 9 9 9 7 7 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 B = 16 16 16 2 2 2 3 3 3 13 13 13 16 16 16 2 2 2 3 3 3 13 13 13 16 16 16 2 2 2 3 3 3 13 13 13 5 5 5 11 11 11 10 10 10 8 8 8 5 5 5 11 11 11 10 10 10 8 8 8 5 5 5 11 11 11 10 10 10 8 8 8 9 9 9 7 7 7 6 6 6 0 0 0 9 9 9 7 7 7 6 6 6 0 0 0 9 9 9 7 7 7 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 B = 16 16 16 2 2 2 3 3 3 13 13 13 16 16 16 2 2 2 3 3 3 13 13 13 16 16 16 2 2 2 3 3 3 13 13 13 5 5 5 11 11 ...

5   Pass
A = (-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