Cody

# Problem 1121. Make a logical diamond using GALLERY function

Solution 2895017

Submitted on 31 Aug 2020 by malues
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 G = your_fcn_name(n) G = gallery('circul',round(n/2)); G = [fliplr(G(:,2:end)),G] G = [G; flip(G(1:end-1,:))] G(G~=1) = 0 end %This code written by profile_id 12146002 '

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 G = 3 2 1 2 3 2 1 3 1 2 1 3 2 3 1 G = 3 2 1 2 3 2 1 3 1 2 1 3 2 3 1 2 1 3 1 2 3 2 1 2 3 G = 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

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 G = 5 4 3 2 1 2 3 4 5 4 3 2 1 5 1 2 3 4 3 2 1 5 4 5 1 2 3 2 1 5 4 3 4 5 1 2 1 5 4 3 2 3 4 5 1 G = 5 4 3 2 1 2 3 4 5 4 3 2 1 5 1 2 3 4 3 2 1 5 4 5 1 2 3 2 1 5 4 3 4 5 1 2 1 5 4 3 2 3 4 5 1 2 1 5 4 3 4 5 1 2 3 2 1 5 4 5 1 2 3 4 3 2 1 5 1 2 3 4 5 4 3 2 1 2 3 4 5 G = 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

### Community Treasure Hunt

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

Start Hunting!