Can you fill a 8x8 grid with numbers from 1 to 8 such that:
- Every number occurs exactly once in each row and in each column (Latin square).
- No two adjacent (horizontally or vertically) numbers sum to a prime.
Good luck!
Can you fill a 8x8 grid with numbers from 1 to 8 such that:
Good luck!
I think this works:
7 5 3 1 8 6 4 2 5 3 1 8 6 4 2 7 3 1 8 6 4 2 7 5 1 8 6 4 2 7 5 3 8 6 4 2 7 5 3 1 6 4 2 7 5 3 1 8 4 2 7 5 3 1 8 6 2 7 5 3 1 8 6 4
The adjacent number pairs are restricted to
(7,5), (5,3), (3,1), (1,8), (8,6), (6,4), (4,2), (2,7)
where each pair sums to
either an even number (greater than 2) or 9, all of which are composite.
Note that it is necessary to
minimize the boundary between an even and an odd number
because
the only possible odd sums are 9 (allowing four pairs) and 15 (only allowing (7,8)).
Here is another one:
7 5 3 1 8 6 4 2
1 7 5 3 6 4 2 8
3 1 7 5 4 2 8 6
5 3 1 7 2 8 6 4
4 6 8 2 7 1 3 5
2 4 6 8 1 3 5 7
8 2 4 6 3 5 7 1
6 8 2 4 5 7 1 3
Note that for any permutation of the first 4 columns there are 6 matching permutations of the last 4 that give rise to another solution. And similar for rows. So this is actually a family of solutions.
Quite easy using a constraint solver. For example Minizinc language and then using Gecode solver:
include "alldifferent.mzn";
int: N = 8;
array[1..N,1..N] of var 1..N: p;
set of int: not_primes = array2set([4, 6, 8, 9, 10, 12, 14, 15, 16]);
constraint forall(n in 1..N)(
alldifferent([p[n,g] |g in 1..N]) /\ alldifferent([p[g,n] |g in 1..N])
);
constraint forall(n in 1..N, g in 1..(N-1)) (
p[n,g]+p[n,g+1] in not_primes
);
constraint forall(n in 1..N, g in 1..(N-1)) (
p[g,n]+p[g+1,n] in not_primes
);
output [show_int(1,p[i,j])++
if j == N then
if i != N then "\n"
else " " endif
else " " endif
| i,j in 1..N ] ++ ["\n"];
There are millions of solutions. (I didn't wait.).
8 2 4 6 3 1 7 5
6 4 2 8 1 7 5 3
3 5 7 1 8 2 4 6
1 7 5 3 6 4 2 8
5 3 1 7 2 8 6 4
7 1 3 5 4 6 8 2
2 8 6 4 5 3 1 7
4 6 8 2 7 5 3 1
----------
1 5 3 7 2 6 8 4
7 3 1 5 4 2 6 8
5 1 7 3 6 8 4 2
3 7 5 1 8 4 2 6
6 2 4 8 1 5 7 3
2 6 8 4 5 1 3 7
4 8 6 2 7 3 1 5
8 4 2 6 3 7 5 1
----------
7 3 1 5 4 8 6 2
3 7 5 1 8 2 4 6
5 1 3 7 2 6 8 4
1 5 7 3 6 4 2 8
8 4 2 6 3 5 7 1
4 6 8 2 7 1 3 5
2 8 6 4 5 7 1 3
6 2 4 8 1 3 5 7