Cody

Problem 43656. Tent matrix

Solution 1222016

Submitted on 28 Jun 2017 by Noriko Hounoki
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
n = 1; y_correct = 1; assert(isequal(surround(n),y_correct))

c = 1 r1L = 1 r1R = 1 r1 = 1 1 r1 = 1 r2 = [] r1_Lhalf = 1 y = 1 1 y = 1

2   Pass
n=3 y_correct = [1 2 1 2 3 2 1 2 1]; assert(isequal(surround(n),y_correct))

n = 3 c = 2 r1L = 1 2 r1R = 2 1 r1 = 1 2 2 1 r1 = 1 2 1 r2 = [] r2 = 2 3 2 r1 = 1 2 1 2 3 2 r1_Lhalf = 2 3 2 1 2 1 y = 1 2 1 2 3 2 2 3 2 1 2 1 y = 1 2 1 2 3 2 1 2 1

3   Pass
n=5 y_correct = [1 2 3 2 1 2 3 4 3 2 3 4 5 4 3 2 3 4 3 2 1 2 3 2 1]; assert(isequal(surround(n),y_correct))

n = 5 c = 3 r1L = 1 2 3 r1R = 3 2 1 r1 = 1 2 3 3 2 1 r1 = 1 2 3 2 1 r2 = [] r2 = 2 3 4 3 2 r1 = 1 2 3 2 1 2 3 4 3 2 r2 = 3 4 5 4 3 r1 = 1 2 3 2 1 2 3 4 3 2 3 4 5 4 3 r1_Lhalf = 3 4 5 4 3 2 3 4 3 2 1 2 3 2 1 y = 1 2 3 2 1 2 3 4 3 2 3 4 5 4 3 3 4 5 4 3 2 3 4 3 2 1 2 3 2 1 y = 1 2 3 2 1 2 3 4 3 2 3 4 5 4 3 2 3 4 3 2 1 2 3 2 1

4   Pass
n=7 y_correct = [1 2 3 4 3 2 1 2 3 4 5 4 3 2 3 4 5 6 5 4 3 4 5 6 7 6 5 4 3 4 5 6 5 4 3 2 3 4 5 4 3 2 1 2 3 4 3 2 1]; assert(isequal(surround(n),y_correct))

n = 7 c = 4 r1L = 1 2 3 4 r1R = 4 3 2 1 r1 = 1 2 3 4 4 3 2 1 r1 = 1 2 3 4 3 2 1 r2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 7 6 5 4 3 4 5 6 7 8 7 6 5 4 3 2 3 4 5 6 7 6 5 4 3 2 1 2 3 4 5 6 5 4 3 2 1

Community Treasure Hunt

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

Start Hunting!