Discover MakerZone

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

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!

Problem 1697. Make a Pandiagonal Prime Magic Square: 11 x 11

Created by Richard Zapor

This Fun with Primes Challenge is to create a Pandiagonal Prime Magic Square of size 11x11 given eleven APk sequences with 10 constant offsets and 121 unique prime values.

An APk sequence is of the form P + offset(i) where P is a prime and i=1:11 with offset(1)=0 and offset(j)>offset(i), j>i.

A Pandiagonal Magic Square has all rows, columns, diagonals(including broken), and anti-diagonals(including broken) summing to the same value.

Input: APk matrix (11,11)

Output: Pandiagonal Matrix (11,11)


The 11x11 algorithm can be summarized as circular shift of rows to make all columns sum to the same goal value. The goal value is the diagonal sum of the APk matrix. Use Knight moves +2 rows +1 column, with bottom to top wrap.

Detailed Methodolgy:
1) PS : Shift APk rows 2 thru 11 by 2*(row value)
2) First column of PS will be first column of P
3) P from PS row 1 : P(1,1)=PS(1,1), P(3,2)=PS(1,2) or P(delta Knight)=PS(row,next). The P(3,2) is 2 down and 1 over from P(1,1).
4) Repeat Knight moves starting at P(row,1) for the remaining rows.

Related Challenges:

1) Pandiagonal Check

2) Find 11x11 Pandiagonal 18191 APk set

Restrictions: No str2num or regexp (enforced as necessary)

Problem Group

Solution Statistics

5 correct solutions 1 incorrect solutions
Last solution submitted on Sep 30, 2013

Problem Comments

Solution Comments