Problem 4. Make a checkerboard matrix
Solution Stats
Problem Comments
-
38 Comments
This problem is far less trivial than it seems. Fun!
Cool.
Nice
Good one
All solutions with score 10 or 11 use the regexp cheat.
nice one
nice
I like this one! came to know about the invhilb function just because of this!
simple Tricky
This solution works on matlab but not here.
function a = checkerboard(n)
theta=pi/2:pi/2:n*pi/2;
a = (sin(theta)'*sin(theta))+cos(theta)'*cos(theta);
end
very good
This is a good problem!
Very nice! ;)
nice!
It is good problem!
good
Good!
Good
Good one
good one
I can not ...
nice problem
Nice
Puzzled me a bit but I'm proud of the final result even if i did 47 lines of code for this haha!
Nice
Nice - I can think of a few ways to do this. I dislike for loops in general so i try to minimise use, but ended up with a single reduced for loop and an eye commands. Enjoy!
function a = checkerboard(n)
a = ones(n);
a(2:2:n^2)=0;
end this code give me right answer in soft,but failed here
Good problem. Helps to understand the uses of logical operators.
The even part n=4 is tricky, Hint: google it
%% cherboard
function [board] = Chekerboard(n)
%% set bord matrix with zeros
board = zeros(n,n);
for j = 1:n
if mod(j,2)==0 %if zero row is even
for i =1:2:n
board(j,i) = 1;
end
else mod(j,2)==1 %if 1, row is odd
for t = 2:2:n
board(j,t) = 1;
end
end
end
this works and easy to understand~
function a = checkerboard(n)
if mod(n,2)==1
b = ones(n,n);
for i=2:2:n^2
b(i)=0;
end
a=b;
else
b = ones(n+1);
for i=2:2:(n+1)^2
b(i)=0;
end
a=b(1:n,1:n);
end
end
I just made
a(2:2:n,1:2:n) = 0;
a(1:2:n,2:2:n) = 0;
rather easy actually
What is the "size" of the solved problem? How is it calculated?
Awesome!
Nice problem :)
Fun problem with different solutions!
Nice problem, but tests 6 and 8 seem to make no sense. They use same input to the function, but expects different output, thus making it impossible to solve it.
Can someone please confirm?
@Adam, that test case was left incomplete, as there was some problem on my end as I was updating the problem.
I have now edited the test suite and have re-scored your solution as well.
Solution Comments
Show commentsProblem Recent Solvers15766
Suggested Problems
-
840 Solvers
-
Magic is simple (for beginners)
9187 Solvers
-
737 Solvers
-
1401 Solvers
-
Convert from Fahrenheit to Celsius
23820 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!