Re: [Algorithms] Magic Square
Brought to you by:
vexxed72
From: Jamie F. <j.f...@re...> - 2000-11-09 15:02:43
|
I seem to remember them having a very simple construction algorithm (which I don't have time to test now, so I may well be wrong). Pick a square to start in (doesn't matter where, I think), then move like a knight (in chess) from that position, laying down the next number each time you land. Wrap at the edges. There may be a special case I've forgotten; if so, it was only one. Unless my memory is completely shot... that was school work some time ago :) Ah: special case was when you tried to lay a number down somewhere already filled; then you jumped one to the side in the direction equal to the shorter axis of the move of the knight. I think :) Jamie Jaakko Westerholm wrote: > This is probably OT, and I really shouldn't ask this cause this is a problem that is part of a contest.. (and sorry about my english) but still I want to know what would be the fastest way of doing this.. > > So the problem is that I wanted to make a program which makes n*n magic square (1<=n<=20 .. all the rows and columns sum up as the same and diagonals too but there isn't need for that.. and the numbers are 1,2, ..., n*n and every number can be used only once). And some of the numbers would also been given by the user (but not necessarely).. > I have my own solution to this but I don't know if it's the fastest and I would really want to know if there is a very fast way of solving this.. maybe with matrices.. > > > _______________________________________________ > GDAlgorithms-list mailing list > GDA...@li... > http://lists.sourceforge.net/mailman/listinfo/gdalgorithms-list -Virus Scanned and cleared ok |