Results 1 to 15 of 15
Thread: Magic squares LUX method
- 04-13-2010, 04:20 AM #1
Member
- Join Date
- Feb 2010
- Posts
- 75
- Rep Power
- 0
Magic squares LUX method
Hey, I'm trying to make a program that will make a magic square of any order. But I can't figure out how to implement the LUX method. I would love to give you what I have, but I really have no clue how to do it. Could you just give me some pseudocode? I can write the specifics, I am just completely lost on how to start. I have an array, and that's about it. Thank you SO much. I can't explain how the lux method works in text, so google it if you don't know what I'm talking about.
Edit: Here's a link:http://mathworld.wolfram.com/MagicSquare.html Scroll about halfway down the page. And yes, this is my homework, but I don't need an entire program. Just the pseudocode for one method.Last edited by gandalf5166; 04-13-2010 at 04:37 AM.
- 04-13-2010, 04:19 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Could you explain what LUX method do. I'm lazy to read that entire page lol.
- 04-13-2010, 04:43 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
But the pseudo code (in plain English) is in that link. You basically create an odd size magic square but each square actually is made up of 2x2 squares. You have to fill each qraduple according to either the L, U or X shape. Carefully read the text in that link again.
kind regards,
Jos
- 04-13-2010, 05:18 PM #4
Member
- Join Date
- Feb 2010
- Posts
- 75
- Rep Power
- 0
Yeah, but I can't figure out how to do it with a computer. As far as I can tell, it's only really doable by a human being. Either that, or I don't know enough about Java to do it. And Eranga, here's the relevant paragraph, copy and pasted from the site.

A very elegant method for constructing magic squares of singly even order n=4m+2 with m>=1 (there is no magic square of order 2) is due to J. H. Conway, who calls it the "LUX" method. Create an array consisting of m+1 rows of Ls, 1 row of Us, and m-1 rows of Xs, all of length n/2=2m+1. Interchange the middle U with the L above it. Now generate the magic square of order 2m+1 using the Siamese method centered on the array of letters (starting in the center square of the top row), but fill each set of four squares surrounding a letter sequentially according to the order prescribed by the letter. That order is illustrated on the left side of the above figure, and the completed square is illustrated to the right. The "shapes" of the letters L, U, and X naturally suggest the filling order, hence the name of the algorithm.
- 04-13-2010, 05:32 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Instead of marking those quadruples of squares with L, U or X mark them with 0, 1 and 2; have two 2x4 arrays ready: int[][] dx and int[][] dy as follows:
For any square at (x, y) and marked 0, 1 or 2 walk over the magic square for the x_i+1= x_i+dx[mark][i] and y_i+1= y_i+dy[mark][i] for the values i= 0, 1, 2 and 3 (all four squares in a quadruple. The value of 'mark' is 0, 1 or 2 given the current quadruple. You can figure out the rest.Java Code:int[][] dx= { { 1, -1, 1, -1 }, { 0, 0, 1, 0 }, { 0, 1, -1, 1 } }; // x direction for L, U or X int[][] dy= { { 0, 1, 0, -1 }, { 0, 1, 0, -1 }, { 0, 1, 0, 01 } }; // y direction for L, U or X
kind regards,
JosLast edited by JosAH; 04-13-2010 at 05:38 PM.
- 04-13-2010, 05:34 PM #6
Member
- Join Date
- Feb 2010
- Posts
- 75
- Rep Power
- 0
I haven't quite figured out what you said yet, but I'm sure I'll figure it out. Thank you!
- 04-13-2010, 05:36 PM #7
Member
- Join Date
- Feb 2010
- Posts
- 75
- Rep Power
- 0
Ok, I think I get it now.
- 04-16-2010, 08:35 PM #8
Member
- Join Date
- Feb 2010
- Posts
- 75
- Rep Power
- 0
Ok, I don't really get it. I've only just been introduced to arrays. What you just said doesn't really make sense. Could you explain it to me in English, and maybe show me an example? And please, just an example, I really do want to learn how to do it.
- 04-16-2010, 08:41 PM #9
Member
- Join Date
- Feb 2010
- Posts
- 75
- Rep Power
- 0
No, I get it now. Those are two-dimensional arrays showing the change in each coordinate. So the {}'s declare each set of four as 0, 1, and 2? But then how would I move up and to the right a whole set of four? I wouldn't know where I was, since the different letters end in different places. Also, would I create a separate array that had the different "letters" in it? Or could that somehow be done within the square? And if it would have to be in a different array, how would I access it in such a way that it would correspond to the real one, which would be four times bigger?
- 04-16-2010, 08:55 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
You always start at the upper left corner of each 2x2 square by using two simple loops:
In the body of the inner loop you use the dy and dx arrays to traverse those 2x2 little squares. But first you check the value of the big square magic[yy][xx] which dx and dy arrays to use (a 0, 1 or 2 value for an L, U, X move). Of course you overwite that magic[yy][xx] value but you don't care because after you have filled in the correct values you never consult it again and you don't care 'where you end' because you fill in the next 2x2 square the next time you go through the loops.Java Code:for (int y= 0; y < n; y+=2) { for((int x= 0; x < n; x+=2) { int yy= y; // top of little 2x2 square int xx= x; // left of little 2x2 square // ... } }
kind regards,
Jos
- 04-16-2010, 09:06 PM #11
Member
- Join Date
- Feb 2010
- Posts
- 75
- Rep Power
- 0
Two questions. What is n? And I can't tell, are you saying that I do need two arrays? Edit: I get it,I'm making an array with the "letters" and an array that is the square, calculating that since I'm at the upper left of the little square then I can know where I am in relation to the "letters" array. Still don't know what n is though.
Last edited by gandalf5166; 04-16-2010 at 09:10 PM.
- 04-17-2010, 02:02 AM #12
Member
- Join Date
- Feb 2010
- Posts
- 75
- Rep Power
- 0
badadabump
- 04-17-2010, 08:24 AM #13
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
'n' is the size of a side of your magic square; first you have to fill it with the values 0, 1 and 2 (for the values L, U and X); the next pass fills it with the values for the final magic square as I described before. The dx and dy arrays indeed describe the geometric shapes for L, U and X for each 2x2 square. Those are all the arrays you need: one big magic square array and two small direction arrays (those are the dx and dy arrays)
kind regards,
Jos
- 04-17-2010, 03:43 PM #14
Member
- Join Date
- Feb 2010
- Posts
- 75
- Rep Power
- 0
Thank you so much! This is due tonight and there is almost no way I would be able to have it done by then without your help.
- 04-17-2010, 04:30 PM #15
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Don't forget to 'walk' over that magic square nxn as if it were a magic sqare of odd size (n/2)x(/2). Maybe if you google for "magic square Horsmeier" you can find a solution of mine that enumerates the values for an odd size square from left to right, top to bottom.
kind regards,
Jos
Similar Threads
-
Calculating Squares and Cubes in a table
By aldorfski_17 in forum New To JavaReplies: 4Last Post: 03-22-2010, 07:17 PM -
Magic Square!!!... :D
By joms999 in forum New To JavaReplies: 4Last Post: 02-25-2010, 07:55 AM -
Magic Eightball
By sachmow in forum New To JavaReplies: 1Last Post: 11-15-2009, 04:37 PM -
help with perfect squares
By AmplifiedKid in forum New To JavaReplies: 1Last Post: 09-19-2009, 07:44 PM -
Perfect Squares
By divyachaparala in forum New To JavaReplies: 4Last Post: 02-05-2008, 09:21 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks