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)
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.
I had not recognized the symmetry of row and column processing. A very succinct method to create a Knight pattern.
Find the numeric mean of the prime numbers in a matrix.
5913 Solvers
Project Euler: Problem 1, Multiples of 3 and 5
1064 Solvers
57 Solvers
27 Solvers
Flag largest magnitude swings as they occur
524 Solvers