in reply to Better algorithm for Number Place Puzzle
I think in your description you made one typo:
For example, if N=5, the puzzle has 25 columns, ...
.. I think should have said "if sqrt(N)=5".
To approach this, first off I don't see any reason to choose random numbers: for a 36x36 square, there are at most 36 numbers to consider, so it seems strange to pick 10,000 random numbers rather than just try each of the 36 in turn.
Second, the numbers have no intrinsic meaning, they are just labels - you could colour the squares using 36 different colours, and you'd still be solving the same problem. That implies in particular that given any solution you could swap, say, all the 1s and 2s around and have a new solution - it is just a different way of labelling the 36 colours using numbers. Given that, you might as well choose a fixed labelling by pre-filling the first row with the numbers in order.
Third, there is a very easy way to construct a magic NxN square for any odd N, and I suspect a small tweak to that construction would also allow you to construct a solution for this problem for odd N. I've blanked it out below in case you don't want to know.
Create a mask consisting of knight's moves, then shift and repeat. Eg for a 7x7 grid the mask would look like: |
Fourth, you may be able to get substantial speedups by dealing with bit vectors rather than arrays; however, I'd suggest posting your code here for more specific advice.
Hugo
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Better algorithm for Number Place Puzzle
by davidj (Priest) on May 23, 2004 at 22:30 UTC | |
by hv (Prior) on May 24, 2004 at 02:51 UTC | |
by dash2 (Hermit) on May 23, 2004 at 22:35 UTC | |
by davidj (Priest) on May 23, 2004 at 22:53 UTC | |
by Abigail-II (Bishop) on May 23, 2004 at 23:09 UTC | |
by davidj (Priest) on May 23, 2004 at 23:47 UTC | |
by dash2 (Hermit) on May 23, 2004 at 23:12 UTC |