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)
Algorithm:
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:
2) Find 11x11 Pandiagonal 18191 APk set
Restrictions: No str2num or regexp (enforced as necessary)
Solution Stats
Problem Comments
-
4 Comments
Richard, I think your test suite has an error in it. Both pd and pad will result in the same matrix, as they're both circshifted by [1 1-i] Will pad=fliplr(pad); after the for loop correct this problem?
Test Suite fixed. Who new that 1-i is the same as -i+1.
The circular shift should be made from first row, not the 2nd, and the "knight" always moves down from the first column of the row to the last column in an L-movement.
I fully agree with the comments by Rafael S.T. Vieira. The problem is nice but it was badly explained
Solution Comments
Show commentsProblem Recent Solvers14
Suggested Problems
-
1302 Solvers
-
Make a random, non-repeating vector.
9272 Solvers
-
361 Solvers
-
Give me Hamming on five, hold the mayo
48 Solvers
-
549 Solvers
More from this Author308
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!