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

64.29% Correct | 35.71% Incorrect
Last solution submitted on Nov 16, 2014

Problem Comments

Solution Comments

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Join the 15-year community celebration.

Play games and win prizes!

Learn more