What is a Prime Square?
A Prime Square is a square where all four edges are different prime numbers.
But which ones?
And how do we construct them?
Here is an example of a 4x4 Prime Square
1009
0 0
3 0
1021
First we start from the upper left corner. We are working clockwise.
We pick the smallest prime number having 4
digits which is 1009.
Then we need the smallest prime number having 4
digits, which starts with a 9
. This is 9001
The third (4-digits) prime number must have 1
as its last digit (because 9001 ends with 1
)
and also be the smallest 4-digit prime with this property that has not been used before as an edge.
This prime number is 1021
The fourth prime number must have 4
digits, start with a 1
(because 1009 starts with a 1
) and end with a 1
(because 1021 starts with a 1
)
The smallest 4-digit prime number with this property that has not been used before as an edge is 1031
Your TASK
You will be given an integer n
from 3 to 100
This number will be the dimensions of the n x n
square
Then you must output this square exactly in the form of the following test cases
Test Cases
n=3
Output
101
3 0
113
n=5
Output
10007
0 0
0 0
9 0
10061
n=7
Output
1000003
0 0
0 0
0 0
0 0
8 1
1000037
n=10
Output
1000000007
0 0
0 0
0 0
0 0
0 0
0 0
1 0
8 0
1000000021
n=20
Output
10000000000000000051
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
9 8
10000000000000000097
- Input and output can be given by any convenient method.
- You can print it to STDOUT or return it as a function result.
- Either a full program or a function are acceptable.
- Any amount of extraneous whitespace is acceptable, so long as the numbers line up appropriately
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
EDIT
This is possible for all n
Here are the primes for n=100
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000289
9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000091
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000711
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002191
And for those of you that you don't think this is possible [here are ALL the test cases][1]
n
:P? Not a problem with the challenge, just curious. \$\endgroup\$n
: forn
=1, we cannot satisfy the constraint that the four edges are different primes, while forn
=2, we are forced to choose 11,13,23, at which point the final edge is 12 which is composite. I don't have a proof that it is possible for alln
>2, but would be shocked to learn otherwise: informally, the more digits there are, the more "wiggle room" there is to satisfy the constraints. \$\endgroup\$n
there are at least two primes of lengthn
starting with 1 and ending with each of those digits (hence we can choose a bottom edge) and there are at least three primes starting with 1 and ending with 1 (hence we can choose a left edge). \$\endgroup\$