Cody

Problem 42790. Full combinations

Solution 2177142

Submitted on 26 Mar 2020 by Asif Newaz
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))

y = 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1

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

y = 0 -1 -1 0 -1 0 0 -1 1 1 -1 -1 1 -1 0 1 -1 1

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

y = 0 2 4 8 7 6 4 1 1 0

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

y = 6×2 char array 'ac' 'ad' 'ae' 'bc' 'bd' 'be'

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

y = 'aaz'

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

y = 6×2 char array '!2' '!3' '@2' '@3' '#2' '#3'

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

y = 6×8 char array '@matlab$' '@matlab%' '@matlab*' '#matlab$' '#matlab%' '#matlab*'

8   Pass
% 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

y = 1 1 1 1 1 1 1 1 1 2 1 1 1 1 3 1 1 1 1 4 1 1 2 1 1 1 1 2 1 2 1 1 2 1 3 1 1 2 1 4 1 1 3 1 1 1 1 3 1 2 1 1 3 1 3 1 1 3 1 4 1 1 4 1 1 1 1 4 1 2 1 1 4 1 3 1 1 4 1 4 1 1 5 1 1 1 1 5 1 2 1 1 5 1 3 1 1 5 1 4 1 1 6 1 1 1 1 6 1 2 1 1 6 1 3 1 1 6 1 4 1 1 7 1 1 1 1 7 1 2 1 1 7 1 3 1 1 7 1 4 1 1 8 1 1 1 1 8 1 2 1 1 8 1 3 1 1 8 1 4 1 1 9 1 1 1 1 9 1 2 1 1 9 1 3 1 1 9 1 4 1 1 10 1 1 1 1 10 1 2 1 1 10 1 3 1 1 10 1 4 1 2 1 1 1 1 2 1 1 2 1 2 1 1 3 1 2 1 1 4 1 2 2 1 1 1 2 2 1 2 1 2 2 1 3 1 2 2 1 4 1 2 3 1 1 1 2 3 1 2 1 2 3 1 3 1 2 3 1 4 1 2 4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 5 1 2 1 7 5 1 3 1 7 5 1 4 1 7 6 1 1 1 7 6 1 2 1 7 6 1 3 1 7 6 1 4 1 7 7 1 1 1 7 7 1 2 1 7 7 1 3 1 7 7 1 4 1 7 8 1 1 1 7 8 1 2 1 7 8 1 3 1 7 8 1 4 1 7 9 1 1 1 7 9 1 2 1 7 9 1 3 1 7 9 1 4 1 7 10 1 1 1 7 10 1 2 1 7 10 1 3 1 7 10 1 4 1 8 1 1 1 1 8 1 1 2 1 8 1 1 3 1 8 1 1 4 1 8 2 1 1 1 8 2 1 2 1 8 2 1 3 1 8 2 1 4 1 8 3 1 1 1 8 3 1 2 1 8 3 1 3 1 8 3 1 4 1 8 4 1 1 1 8 4 1 2 1 8 4 1 3 1 8 4 1 4 1 8 5 1 1 1 8 5 1 2 1 8 5 1 3 1 8 5 1 4 1 8 6 1 1 1 8 6 1 2 1 8 6 1 3 1 8 6 1 4 1 8 7 1 1 1 8 7 1 2 1 8 7 1 3 1 8 7 1 4 1 8 8 1 1 1 8 8 1 2 1 8 8 1 3 1 8 8 1 4 1 8 9 1 1 1 8 9 1 2 1 8 9 1 3 1 8 9 1 4 1 8 10 1 1 1 8 10 1 2 1 8 10 1 3 1 8 10 1 4 1 9 1 1 1 1 9 1 1 2 1 9 ...

Suggested Problems

More from this Author30

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!