Cody

Solution 860845

Submitted on 1 Apr 2016
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
x1 = [0 1]; x2 = [0 1]; x3 = [0 1]; y_correct = [0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1]; assert(isequal(myfullfact(x1,x2,x3),y_correct))

2   Pass
x1 = [0 1]; x2 = [-1]; x3 = [-1 0 1]; y_correct = [0 -1 -1 0 -1 0 0 -1 1 1 -1 -1 1 -1 0 1 -1 1]; assert(isequal(myfullfact(x1,x2,x3),y_correct))

3   Pass
x1 = 0; x2 = 2; x3 = 4; x4 = 8; x5 = 7; x6 = 6; x7 = 4; x8 = 1; x9 = 1; x10 = 0; y_correct = [x1 x2 x3 x4 x5 x6 x7 x8 x9 x10]; assert(isequal(myfullfact(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10),y_correct))

4   Pass
x1 = 'ab'; x2 = 'cde'; y_correct = ['ac' 'ad' 'ae' 'bc' 'bd' 'be']; assert(isequal(myfullfact(x1,x2),y_correct))

5   Pass
x1 = 'a'; x2 = 'a'; x3 = 'z'; y_correct = 'aaz'; assert(isequal(myfullfact(x1,x2,x3),y_correct))

6   Pass
x1 = '!@#'; x2 = '23'; y_correct = ['!2' '!3' '@2' '@3' '#2' '#3']; assert(isequal(myfullfact(x1,x2),y_correct))

7   Pass
x1 = '@#'; x2 = 'm'; x3 = 'a'; x4 = 't'; x5 = 'l'; x6 = 'a'; x7 = 'b'; x8 = '$%*'; y_correct = ['@matlab$' '@matlab%' '@matlab*' '#matlab$' '#matlab%' '#matlab*']; assert(isequal(myfullfact(x1,x2,x3,x4,x5,x6,x7,x8),y_correct))

8   Fail
% A manual implementation used to validate other solutions. Please be advised that generalization of this is straightforward but inefficient in terms of Cody size. To get a solution with possibly smaller size, try different ideas please. for iter = 1:20 a = randi(10,5,1); x = arrayfun(@(x)(1:x).',a,'un',0); [x1,x2,x3,x4,x5] = deal(x{:}); y1 = repelem(x1, prod(a(2:5)), 1); y2 = repmat(repelem(x2, prod(a(3:5)), 1), a(1), 1); y3 = repmat(repelem(x3, prod(a(4:5)), 1), prod(a(1:2)), 1); y4 = repmat(repelem(x4, a(5), 1), prod(a(1:3)), 1); y5 = repmat(x5, prod(a(1:4)), 1); y_correct = [y1, y2, y3, y4, y5]; assert(isequal(myfullfact(x1,x2,x3,x4,x5),y_correct)); end

Error using myfullfact (line 7) Dimensions of matrices being concatenated are not consistent.