Adjacent squares include the central square but no diagonal squares are considered. You are right it is very, very tough.
]]>I remember that discussion now about stefy's puzzle, but had to let it go then as I didn't have the first clue as to how to go about solving it...and still don't.
Btw, I initially wondered if 'two adjacent squares' included the central square and if 'adjacent' included 'diagonally adjacent', but from my reading of later posts in the discussion it seems that the answer to both questions is 'no'.
]]>But brekkie first...!
]]>I meant the anonimnystefy problem which is a square problem but not a latin square. It is much, much larger than these.
]]>For a 5 x 5 there are over 209 million.
Re the SE 5x5, ubpdqn says, "there are 56 reduced forms and 161280 overall". Also, OEIS A002860.
For the 7 x 7 problem there are only 24 solutions
They're just the ones I found with that solver add-in, but I've no doubt that there are many more. The add-in is an optimisation program that gives one answer, and by changing numbers in a particular constraint I was able to extract further answers from it. I couldn't see an option to get all solutions.
The above OEIS link says there are 61,479,419,904,000 Latin squares for a 7x7.
]]>I was a little vague in what I meant. We can consider two types of solutions, one is when the solution just spits out the number of ways something can be done. Like, there are 120 ways to permute the digits 1,2,3,4,5. Another type would generate all the solutions and find all 120 of them or look at a lots of them and find the 120.
For the 7 x 7 problem there are only 24 solutions which means either approach can be used. But for anonimnystefy's problem 3 x 3 there are 433 solutions. For a 5 x 5 there are over 209 million. I do not have any idea what an 11 x 11 has, but the number must be beyond astronomical. So, we do not have the luxury of a solver that gets them all or looks at a lot of them. There is no place to print or hold the list. This fact leaves most computer attempts out. We need something that just spits out the answer without counting anything. This will require the use of mathematics and lots of it.
]]>Will your work help you with anonimnystefy's square problem?
He wants a 11 x 11 so it is unlikely that any counting them up is going to work. An analytical solution using Markov chains or maybe Cellular Automata. At present I could not get them to work.
For your 7 x 7, this 5 x 5 was my first ever for a square problem. I can go faster by using partitions rather than permutations.
]]>That's exactly what my problem needed...a full Latin Square list that could be searched for all answers. And the solution also lists the other two duplicate answers I found yesterday.
On my PC, compiling the list takes about 14 seconds, plus a further second for the search.
The 'ans' variable also runs in ubpdqn's (SE) code (replace 'ls /@ Permutations[Range[5]]' with 'ans')...change his criteria too, of course. Search output is the same as yours, and time is about 1 second.
This morning I generated a dummy 161280 list in a 'For' loop, incorporating two correct answers. That took 1 minute, and ubpdqn's code then found those two answers in 1 second.
So...now we're getting really close to solving a 7x7 for all answers! At your 5x5's speed it would only take about 170 years to compile the 7x7 list, plus a further 12 years to find all the answers.
Will your work help you with anonimnystefy's square problem?
]]>Run this for a surprise.
r1 = Permutations[{1, 2, 3, 4, 5}];
ans = ParallelTable[
r2 = Select[r1, Count[# - r1[[k]], 0] == 0 &];
Table[r3 = Select[r2, Count[# - r2[[m]], 0] == 0 &];
Table[r4 = Select[r3, Count[# - r3[[n]], 0] == 0 &];
Table[r5 = Select[r4, Count[# - r4[[q]], 0] == 0 &];
{r1[[k]], r2[[m]], r3[[n]], r4[[q]], r5[[1]]},
{q, 1, Length[r4]}],
{n, 1, Length[r3]}],
{m, 1, Length[r2]}],
{k, 1, Length[r1]}];
ans = Flatten[ans, 3];
ans = Select[
ans, #[[1, 1]] + #[[1, 2]] + #[[1, 3]] + #[[2, 1]] + #[[2,
3]] + #[[3, 1]] + #[[3, 2]] + #[[3, 3]] ==
21 && #[[1, 3]] + #[[1, 4]] + #[[1, 5]] + #[[2, 3]] + #[[2,
5]] + #[[3, 3]] + #[[3, 4]] + #[[3, 5]] == 24 &];
ans = Select[
ans, #[[3, 1]] + #[[3, 2]] + #[[3, 3]] + #[[4, 1]] + #[[4,
3]] + #[[5, 1]] + #[[5, 2]] + #[[5, 3]] ==
22 && #[[3, 3]] + #[[3, 4]] + #[[3, 5]] + #[[4, 3]] + #[[4,
5]] + #[[5, 3]] + #[[5, 4]] + #[[5, 5]] == 21 &];
MatrixForm[#] & /@ ans