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

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)

Solution Stats

81.25% Correct | 18.75% Incorrect
Last Solution submitted on Apr 12, 2023

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers14

Suggested Problems

More from this Author308

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!