Problem 780. Give a matrix that matches itself when rotated
Given n and s, return a n-by-n matrix a of integers such that
sum(sum(a == rot90(a)))
is equal to exactly s. The integers should be chosen from the set 1 to n.
So for instance, if n is 2, and s is 2, you could return
a = [ 1 1 2 2 ]
since rot90(a) matches a in exactly one place.
For any n and s, a is of course not unique. I'm only checking to make sure the conditions are true.
Solution Stats
Problem Comments
-
5 Comments
s=feval(@evalin,'caller','s');
Lack of s input solved
Sorry guys. Sloppy problem creation on my part. Unfortunately my signature change will invalidate all the solutions up to this point, but yes it should be match_rot(n,s)
"since rot90(a) matches a in exactly _two_ places" for the example in the problem statement?
Solution Comments
Show commentsProblem Recent Solvers13
Suggested Problems
-
Return the largest number that is adjacent to a zero
5407 Solvers
-
3413 Solvers
-
1220 Solvers
-
Replace all zeros and NaNs in a matrix with the string 'error'
100 Solvers
-
Find last zero for each column
591 Solvers
More from this Author50
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!