Cody

Problem 803. Twist 'n' Match

Given n and m, construct an n-by-n matrix a such that a, when rotated 90 degrees and compared with itself, matches itself in exactly m places.

The number of matches m is calculated as follows:

 m = nnz(rot90(a)==a)

Your answer a is clearly not unique. It must only meet the criteria stated above.

Examples:

 Input n = 2, m = 1
 One possible output: a = [ 1 2 
                            1 3 ]
 Input n = 3, m = 7
 One possible output: a = [ 0 1 1
                            1 1 1
                            1 1 1 ]

Solution Stats

70.83% Correct | 29.17% Incorrect
Last solution submitted on Oct 31, 2014

Problem Comments

Tags

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