Cody

Problem 1121. Make a logical diamond using GALLERY function

Solution 1938775

Submitted on 17 Sep 2019 by Augusto Mazzei
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 C = your_fcn_name(n) %gallery:P <--this passed the 1st test anyway .__. C = gallery('cauchy',[1:round(n/2) fix(n/2):-1:1],[1:round(n/2) fix(n/2):-1:1]) C = C==1/(round(n/2)+1) end %This code written by profile_id 8179227 '

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 C = 0.5000 0.3333 0.2500 0.3333 0.5000 0.3333 0.2500 0.2000 0.2500 0.3333 0.2500 0.2000 0.1667 0.2000 0.2500 0.3333 0.2500 0.2000 0.2500 0.3333 0.5000 0.3333 0.2500 0.3333 0.5000 C = 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

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 C = 0.5000 0.3333 0.2500 0.2000 0.1667 0.2000 0.2500 0.3333 0.5000 0.3333 0.2500 0.2000 0.1667 0.1429 0.1667 0.2000 0.2500 0.3333 0.2500 0.2000 0.1667 0.1429 0.1250 0.1429 0.1667 0.2000 0.2500 0.2000 0.1667 0.1429 0.1250 0.1111 0.1250 0.1429 0.1667 0.2000 0.1667 0.1429 0.1250 0.1111 0.1000 0.1111 0.1250 0.1429 0.1667 0.2000 0.1667 0.1429 0.1250 0.1111 0.1250 0.1429 0.1667 0.2000 0.2500 0.2000 0.1667 0.1429 0.1250 0.1429 0.1667 0.2000 0.2500 0.3333 0.2500 0.2000 0.1667 0.1429 0.1667 0.2000 0.2500 0.3333 0.5000 0.3333 0.2500 0.2000 0.1667 0.2000 0.2500 0.3333 0.5000 C = 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

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!