Cody

Problem 45404. ZigZag - 04

Solution 2222597

Submitted on 19 Apr 2020
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 = magic(4); y=[16 2 3 13 8 12 1 15 14 4 9 5 11 10 6 7] assert(isequal(spiral_pattern(x),y))

y = 16 2 3 13 8 12 1 15 14 4 9 5 11 10 6 7 c = 4

2   Fail
x=reshape([89:124],3,[]); y=[89 92 95 98 101 104 107 110 113 116 119 122 123 124 121 118 115 112 109 106 103 100 97 94 91 90 93 96 99 102 105 108 111 114 117 120] assert(isequal(spiral_pattern(x),y))

y = Columns 1 through 29 89 92 95 98 101 104 107 110 113 116 119 122 123 124 121 118 115 112 109 106 103 100 97 94 91 90 93 96 99 Columns 30 through 36 102 105 108 111 114 117 120 c = 3

Index in position 1 exceeds array bounds (must not exceed 3). Error in spiral_pattern (line 6) y=[y,x(a,b:d-1),x(b:c-1,d)', flip(x(c,b+1:d)),flip(x(a+1:c,b))']; Error in Test2 (line 3) assert(isequal(spiral_pattern(x),y))

3   Fail
x = ones(8,2); y=ones(1,16); assert(isequal(spiral_pattern(x),y))

c = 8

Index in position 2 is invalid. Array indices must be positive integers or logical values. Error in spiral_pattern (line 6) y=[y,x(a,b:d-1),x(b:c-1,d)', flip(x(c,b+1:d)),flip(x(a+1:c,b))']; Error in Test3 (line 3) assert(isequal(spiral_pattern(x),y))

4   Fail
x = [17 24 1 23 5 1 4 6 1 10 12 1 11 18 1] y=[17 24 1 1 1 1 1 18 11 10 4 23 5 6 12] assert(isequal(spiral_pattern(x),y))

x = 17 24 1 23 5 1 4 6 1 10 12 1 11 18 1 y = 17 24 1 1 1 1 1 18 11 10 4 23 5 6 12 c = 5

Index in position 2 is invalid. Array indices must be positive integers or logical values. Error in spiral_pattern (line 6) y=[y,x(a,b:d-1),x(b:c-1,d)', flip(x(c,b+1:d)),flip(x(a+1:c,b))']; Error in Test4 (line 7) assert(isequal(spiral_pattern(x),y))

5   Fail
x = magic(9); y=[47 58 69 80 1 12 23 34 45 46 56 66 76 5 15 25 35 24 13 2 81 70 59 48 37 36 26 16 6 77 67 57 68 79 9 11 22 33 44 54 55 65 75 4 14 3 73 71 60 49 38 28 27 17 7 78 8 10 21 32 43 53 63 64 74 72 61 50 39 29 19 18 20 31 42 52 62 51 40 30 41] assert(isequal(spiral_pattern(x),y))

y = Columns 1 through 29 47 58 69 80 1 12 23 34 45 46 56 66 76 5 15 25 35 24 13 2 81 70 59 48 37 36 26 16 6 Columns 30 through 58 77 67 57 68 79 9 11 22 33 44 54 55 65 75 4 14 3 73 71 60 49 38 28 27 17 7 78 8 10 Columns 59 through 81 21 32 43 53 63 64 74 72 61 50 39 29 19 18 20 31 42 52 62 51 40 30 41 c = 9

Assertion failed.