Cody

Problem 591. Create a patchwork matrix

Solution 1938743

Submitted on 17 Sep 2019 by Augusto Mazzei
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
P = [1 0; 1 2]; m1 = eye(2); m2 = ones(2); M_correct = [1 0 0 0; 0 1 0 0; 1 0 1 1; 0 1 1 1]; assert(isequal(patchworkMatrix(P,m1,m2),M_correct))

M = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ans = 1 2 ans = 1 2 ans = 1 ans = 3 4 ans = 1 2 ans = 1 ans = 1 2 ans = 3 4 ans = 0 ans = 3 4 ans = 3 4 ans = 2 1 0 0 0 0 1 0 0 1 0 1 1 0 1 1 1

2   Pass
P = 2-eye(4); m1 = eye(2); m2 = ones(2); M_correct = [1 0 1 1 1 1 1 1; 0 1 1 1 1 1 1 1; 1 1 1 0 1 1 1 1; 1 1 0 1 1 1 1 1; 1 1 1 1 1 0 1 1; 1 1 1 1 0 1 1 1; 1 1 1 1 1 1 1 0; 1 1 1 1 1 1 0 1]; assert(isequal(patchworkMatrix(P,m1,m2),M_correct))

M = 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 ans = 1 2 ans = 1 2 ans = 1 ans = 3 4 ans = 1 2 ans = 2 ans = 5 6 ans = 1 2 ans = 2 ans = 7 8 ans = 1 2 ans = 2 ans = 1 2 ans = 3 4 ans = 2 ans = 3 4 ans = 3 4 ans = 1 ans = 5 6 ans = 3 4 ans = 2 ans = 7 8 ans = 3 4 ans = 2 ans = 1 2 ans = 5 6 ans = 2 ans = 3 4 ans = 5 6 ans = 2 ans = 5 6 ans = 5 6 ans = 1 ans = 7 8 ans = 5 6 ans = 2 ans = 1 2 ans = 7 8 ans = 2 ans = 3 4 ans = 7 8 ans = 2 ans = 5 6 ans = 7 8 ans = 2 ans = 7 8 ans = 7 8 ans = 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 1

3   Pass
P = [2 3 2 3]; m1 = 1; m2 = 2; m3 = 3; M_correct = [2 3 2 3]; assert(isequal(patchworkMatrix(P,m1,m2,m3),M_correct))

M = 0 0 0 0 ans = 1 ans = 1 ans = 2 ans = 1 ans = 2 ans = 3 ans = 1 ans = 3 ans = 2 ans = 1 ans = 4 ans = 3 2 3 2 3

4   Pass
P = [6 5; 4 3; 2 1]; m1 = rand(2,3); m2 = rand(2,3); m3 = rand(2,3); m4 = rand(2,3); m5 = rand(2,3); m6 = rand(2,3); M_correct = [m6 m5; m4 m3; m2 m1]; assert(isequal(patchworkMatrix(P,m1,m2,m3,m4,m5,m6),M_correct))

M = 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 ans = 1 2 ans = 1 2 3 ans = 6 ans = 3 4 ans = 1 2 3 ans = 4 ans = 5 6 ans = 1 2 3 ans = 2 ans = 1 2 ans = 4 5 6 ans = 5 ans = 3 4 ans = 4 5 6 ans = 3 ans = 5 6 ans = 4 5 6 ans = 1 0.8011 0.1894 0.6264 0.3640 0.0653 0.5831 0.0231 0.3121 0.7402 0.5354 0.6531 0.8445 0.0730 0.5328 0.0966 0.1484 0.0790 0.9351 0.1533 0.1292 0.7256 0.5884 0.8271 0.7461 0.4714 0.6318 0.1277 0.7250 0.6158 0.2950 0.8517 0.4688 0.8527 0.4047 0.9071 0.8833

5   Pass
P = zeros(2); m1 = rand(3,2); m2 = rand(3,2); m3 = rand(3,2); m4 = rand(3,2); m5 = rand(3,2); m6 = rand(3,2); M_correct = zeros(6,4); assert(isequal(patchworkMatrix(P,m1,m2,m3,m4,m5,m6),M_correct))

M = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ans = 1 2 3 ans = 1 2 ans = 0 ans = 4 5 6 ans = 1 2 ans = 0 ans = 1 2 3 ans = 3 4 ans = 0 ans = 4 5 6 ans = 3 4 ans = 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

6   Pass
P = []; m = cell(100); assert(isempty(patchworkMatrix(P,m{:})))

M = []