in reply to Re: Better algorithm for Number Place Puzzle
in thread Better algorithm for Number Place Puzzle

hv,

First, You are correct. I did make a typo which you successfully caught. Thank you.

Second, I don't know how magic squares would help. The constraints are totally different. That is, I don't see how meeting the constraints of a magic square puzzle would successfully meet the constraints of the number place puzzle.

Third, you are right. It would be easy to generate a single solution by simply shifting the numbers on each row, and then using matrix rules to generate other solutions, but that would take the fun out of it :)

Finally, my concern at this point is not speed. Rather, it is the effectiveness of an algorithm to generate solutions of any size.

davidj
  • Comment on Re: Re: Better algorithm for Number Place Puzzle

Replies are listed 'Best First'.
Re: Re: Re: Better algorithm for Number Place Puzzle
by hv (Prior) on May 24, 2004 at 02:51 UTC

    I don't know how magic squares would help. The constraints are totally different.

    If you take a standard (N x N) magic square, consisting of the numbers from 1 .. N^2, and then reduce each number module N, you will in some (all?) cases get a square consisting of the numbers 1 .. N such that each number appears exactly once in each row and column.

    The nature of your squares is identical to this case, except for the additional constraint that the N interior squares must each contain each number once. So solutions to this problem are a subset of the (n^2 x n^2) magic squares.

    For this sort of problem I'm more used to either a) showing that there is a solution (any solution) by finding one; or b) finding all solutions. In your case you seem to be aiming at a quite different goal, in which randomness plays a necessary part, but I'm not at all clear what your precise goal is.

    Finally, my concern at this point is not speed. Rather, it is the effectiveness of an algorithm to generate solutions of any size.

    Hmm, so when failing to find a solution in 500,000 random attempts you're concerned not with how long that took but with how many attempts it took? But given that you're selecting the numbers at random, I'm not sure how you'd reduce that except by weighting the numbers towards the ones more likely to give a solution, and I can't offhand see any way to do that without knowing in advance what solutions are possible.

    Sorry, I've realised that I really have no idea what you're asking for.

    Hugo

Re: Re: Re: Better algorithm for Number Place Puzzle
by dash2 (Hermit) on May 23, 2004 at 22:35 UTC
    Mmm. Seems like you think you have an easy solution, but you don't want to use it. What makes you think this problem has more than one solution?
    A massive flamewar beneath your chosen depth has not been shown here
      There is any easy solution: on a 36x36, let the top row be the numbers 1-36, the second row be 2-36,1, the third row be 3-36,1,2, and so on. But that's not the point of the exercise. The point is to find a way to build some intelligence into a program that will randomly generate solutions of any size.

      The problem does have more than one solution. Swapping any two rows or columns of one solution will generate another solution. This can be done repeatedly in any number of combinations to generate thousands of solutions. But again that is not the point of the exercise.

      davidj
        If the top row has numbers 1-36, and the second row has numbers 2-36, 1, then the top right 6x6 grid contains the number 36 twice. It was my understanding that this wasn't allowed.

        Abigail

        Hmm. In a 36x36, using your solution, the top left 6x6 grid would contain multiple 2's-11's.

        I guess if you move 6 along each time? But then after 6 rows you start repeating.

        But OK, fair enough... you're not interested in the algorithm but more in intelligence to find solutions. Well, I guess one thing would be how you approach the search space.

        At the moment, your approach seems to be "start with some numbers then guess some more". Perhaps an alternative approach would be to think of it as an ordering. You have 36 1's, 36 2's.... and 36 36's. This is your set of numbers. Lay your set out in some initial order. See if it works, if not, try swapping two set members at random.

        That's the initial, brute force solution - pretty stupid and slow. The smarts come in when you decide which numbers to swap.

        Gosh, what you are doing sounds like much more fun than the sort of programming I have to do ;-)

        A massive flamewar beneath your chosen depth has not been shown here