Cody

Problem 1121. Make a logical diamond using GALLERY function

Solution 1548221

Submitted on 4 Jun 2018 by Riccardo Dessì
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
filetext = fileread('your_fcn_name.m') assert(~isempty(strfind(filetext, 'gallery'))) assert( isempty(strfind(filetext, '% gallery')))

filetext = 'function y = your_fcn_name(n) gallery('poisson',5) A = eye(ceil(n/2)); Ar = fliplr(A); y = [Ar A(:,2:end);A(2:end,:) Ar(2:end,2:end)]; end %This code written by profile_id 5955064 '

2   Pass
n = 5; expected = [0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0 0]; y_correct = logical(expected) assert(isequal(your_fcn_name(n),y_correct))

y_correct = 5×5 logical array 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0 0 ans = (1,1) 4 (2,1) -1 (6,1) -1 (1,2) -1 (2,2) 4 (3,2) -1 (7,2) -1 (2,3) -1 (3,3) 4 (4,3) -1 (8,3) -1 (3,4) -1 (4,4) 4 (5,4) -1 (9,4) -1 (4,5) -1 (5,5) 4 (10,5) -1 (1,6) -1 (6,6) 4 (7,6) -1 (11,6) -1 (2,7) -1 (6,7) -1 (7,7) 4 (8,7) -1 (12,7) -1 (3,8) -1 (7,8) -1 (8,8) 4 (9,8) -1 (13,8) -1 (4,9) -1 (8,9) -1 (9,9) 4 (10,9) -1 (14,9) -1 (5,10) -1 (9,10) -1 (10,10) 4 (15,10) -1 (6,11) -1 (11,11) 4 (12,11) -1 (16,11) -1 (7,12) -1 (11,12) -1 (12,12) 4 (13,12) -1 (17,12) -1 (8,13) -1 (12,13) -1 (13,13) 4 (14,13) -1 (18,13) -1 (9,14) -1 (13,14) -1 (14,14) 4 (15,14) -1 (19,14) -1 (10,15) -1 (14,15) -1 (15,15) 4 (20,15) -1 (11,16) -1 (16,16) 4 (17,16) -1 (21,16) -1 (12,17) -1 (16,17) -1 (17,17) 4 (18,17) -1 (22,17) -1 (13,18) -1 (17,18) -1 (18,18) 4 (19,18) -1 (23,18) -1 (14,19) -1 (18,19) -1 (19,19) 4 (20,19) -1 (24,19) -1 (15,20) -1 (19,20) -1 (20,20) 4 (25,20) -1 (16,21) -1 (21,21) 4 (22,21) -1 (17,22) -1 (21,22) -1 (22,22) 4 (23,22) -1 (18,23) -1 (22,23) -1 (23,23) 4 (24,23) -1 (19,24) -1 (23,24) -1 (24,24) 4 (25,24) -1 (20,25) -1 (24,25) -1 (25,25) 4

3   Pass
n = 9; expected = [ 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 0] y_correct = logical(expected) assert(isequal(your_fcn_name(n),y_correct))

expected = 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 y_correct = 9×9 logical array 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 ans = (1,1) 4 (2,1) -1 (6,1) -1 (1,2) -1 (2,2) 4 (3,2) -1 (7,2) -1 (2,3) -1 (3,3) 4 (4,3) -1 (8,3) -1 (3,4) -1 (4,4) 4 (5,4) -1 (9,4) -1 (4,5) -1 (5,5) 4 (10,5) -1 (1,6) -1 (6,6) 4 (7,6) -1 (11,6) -1 (2,7) -1 (6,7) -1 (7,7) 4 (8,7) -1 (12,7) -1 (3,8) -1 (7,8) -1 (8,8) 4 (9,8) -1 (13,8) -1 (4,9) -1 (8,9) -1 (9,9) 4 (10,9) -1 (14,9) -1 (5,10) -1 (9,10) -1 (10,10) 4 (15,10) -1 (6,11) -1 (11,11) 4 (12,11) -1 (16,11) -1 (7,12) -1 (11,12) -1 (12,12) 4 (13,12) -1 (17,12) -1 (8,13) -1 (12,13) -1 (13,13) 4 (14,13) -1 (18,13) -1 (9,14) -1 (13,14) -1 (14,14) 4 (15,14) -1 (19,14) -1 (10,15) -1 (14,15) -1 (15,15) 4 (20,15) -1 (11,16) -1 (16,16) 4 (17,16) -1 (21,16) -1 (12,17) -1 (16,17) -1 (17,17) 4 (18,17) -1 (22,17) -1 (13,18) -1 (17,18) -1 (18,18) 4 (19,18) -1 (23,18) -1 (14,19) -1 (18,19) -1 (19,19) 4 (20,19) -1 (24,19) -1 (15,20) -1 (19,20) -1 (20,20) 4 (25,20) -1 (16,21) -1 (21,21) 4 (22,21) -1 (17,22) -1 (21,22) -1 (22,22) 4 (23,22) -1 (18,23) -1 (22,23) -1 (23,23) 4 (24,23) -1 (19,24) -1 (23,24) -1 (24,24) 4 (25,24) -1 (20,25) -1 (24,25) -1 (25,25) 4

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!