in reply to magic squares

And the solution is .... (withdrawn - too many bugs and faulty logic. But I've keep the code in case anyone wants to play with it.).

Update: withdrew solution due to bugs

Replies are listed 'Best First'.
Re^2: magic squares
by ELISHEVA (Prior) on Apr 05, 2009 at 17:52 UTC

    Henry Higgins: By George, she's got it, By George, she's got it. (or so I hope). I finally managed to debug the script and changed the solution strategy... and who do you think doesn't have a magic square to show the teacher?

    On my system the script took 0.69s between 0.40 and 0.48s to print the above output.

    The code follows:

    Update: moved end of spoiler section.

    Update: made two small changes to increase speed by 30-40%

      There is still a bug in your logic. There are over 70 magic squares with all of the letters J O H N and you didn't find most of them.

      Update: I misread the format that ELISHEVA printed her results in. My bad.

        On purpose, but I reread the explanatory portion of my post and I can see how one might have thought otherwise. The algorithm isn't intended to find all of them. Finding one is all that is needed for the stated problem: which student doesn't have a magic square with their name written on it.

        Best, beth