Cody

Problem 782. Some Assembly Required

Solution 1955849

Submitted on 2 Oct 2019 by Eric Mueller
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
x= [1 2 ; 2 3 ; 3 4 ; 4 5]; y_correct=[1 2 3 4 5]; assert(isequal(assemble_this(x),y_correct)||isequal(assemble_this(x),fliplr(y_correct)))

index = 192 y = 1 NaN 2 NaN 3 NaN 4 5 y = 1 2 3 4 5

2   Pass
x= [1 1 2 3 ; 4 5 6 7 ; 5 4 8 3]; y_correct=[1 1 2 3 8 4 5 6 7]; assert(isequal(assemble_this(x),y_correct)||isequal(assemble_this(x),fliplr(y_correct)))

index = 5 y = 1 1 2 NaN 3 8 NaN NaN 4 5 6 7 y = 1 1 2 3 8 4 5 6 7

3   Pass
x=[2 3 ; 4 2 ; 3 1 ; 1 5 ; 5 9]; y_correct=[9 5 1 3 2 4]; assert(isequal(assemble_this(x),y_correct)||isequal(assemble_this(x),fliplr(y_correct)))

index = 1896 y = 4 NaN 2 NaN 3 NaN 1 NaN 5 9 y = 4 2 3 1 5 9 index = 1896 y = 4 NaN 2 NaN 3 NaN 1 NaN 5 9 y = 4 2 3 1 5 9

4   Pass
x=[10:-1:6 ; 1:5 ; 5:0.25:6]; y_correct=[1:4 5:0.25:6 7:10]; assert(isequal(assemble_this(x),y_correct)||isequal(assemble_this(x),fliplr(y_correct)))

index = 11 y = 10.0000 9.0000 8.0000 7.0000 NaN 6.0000 5.7500 5.5000 5.2500 NaN 5.0000 4.0000 3.0000 2.0000 1.0000 y = 10.0000 9.0000 8.0000 7.0000 6.0000 5.7500 5.5000 5.2500 5.0000 4.0000 3.0000 2.0000 1.0000 index = 11 y = 10.0000 9.0000 8.0000 7.0000 NaN 6.0000 5.7500 5.5000 5.2500 NaN 5.0000 4.0000 3.0000 2.0000 1.0000 y = 10.0000 9.0000 8.0000 7.0000 6.0000 5.7500 5.5000 5.2500 5.0000 4.0000 3.0000 2.0000 1.0000

5   Pass
x=[8 16 24 ; 2 4 8 ; 6 4 2]; y_correct=[6 4 2 4 8 16 24]; assert(isequal(assemble_this(x),y_correct)||isequal(assemble_this(x),fliplr(y_correct)))

index = 19 y = 6 4 NaN 2 4 NaN 8 16 24 y = 6 4 2 4 8 16 24

6   Pass
y=ceil(rand*7)+5; ry=[rand(1,y) y]; fry=fliplr([y ry(1:end-1)]); atf=assemble_this([fry ; ry]); y_correct=[y fry]; assert(isequal(atf,y_correct)||isequal(atf,fliplr(y_correct)))

index = 5 y = Columns 1 through 17 9.0000 NaN NaN NaN NaN NaN NaN NaN NaN NaN 0.0473 0.5412 0.6467 0.8951 0.6450 0.9639 0.8265 Columns 18 through 20 0.7263 0.4927 9.0000 y = 9.0000 0.0473 0.5412 0.6467 0.8951 0.6450 0.9639 0.8265 0.7263 0.4927 9.0000

7   Pass
t=rand(1,2); x=[8 16 24 ; 2 4 8 ; 6 4 2 ; 24 t]; at=assemble_this(x); y_correct=[fliplr(t) 24 16 8 4 2 4 6]; assert(isequal(at,y_correct)||isequal(at,fliplr(y_correct)))

index = 178 y = 6.0000 4.0000 NaN 2.0000 4.0000 NaN 8.0000 16.0000 NaN 24.0000 0.7228 0.9303 y = 6.0000 4.0000 2.0000 4.0000 8.0000 16.0000 24.0000 0.7228 0.9303

8   Pass
k=5+ceil(8*rand); x=randperm(k); y=randperm(k)+k; at=assemble_this([x x ; x y]); y_correct=[x x y]; assert(isequal(at,y_correct)||isequal(at,fliplr(y_correct)))

index = 4 y = Columns 1 through 29 2 3 10 12 7 11 1 4 9 6 13 8 5 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 2 3 10 Columns 30 through 52 12 7 11 1 4 9 6 13 8 5 24 16 19 20 21 25 23 15 18 22 17 26 14 y = Columns 1 through 29 2 3 10 12 7 11 1 4 9 6 13 8 5 2 3 10 12 7 11 1 4 9 6 13 8 5 24 16 19 Columns 30 through 39 20 21 25 23 15 18 22 17 26 14

Suggested Problems

More from this Author80

Community Treasure Hunt

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

Start Hunting!