Results 1 to 15 of 15
Thread: Magic squares LUX method
 04132010, 04:20 AM #1Member
 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; 04132010 at 04:37 AM.
 04132010, 04:19 PM #2
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,370
 Blog Entries
 1
 Rep Power
 21
Could you explain what LUX method do. I'm lazy to read that entire page lol.
 04132010, 04:43 PM #3
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,017
 Blog Entries
 7
 Rep Power
 23
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
 04132010, 05:18 PM #4Member
 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 m1 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.
 04132010, 05:32 PM #5
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,017
 Blog Entries
 7
 Rep Power
 23
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:
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; 04132010 at 05:38 PM.
 04132010, 05:34 PM #6Member
 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!
 04132010, 05:36 PM #7Member
 Join Date
 Feb 2010
 Posts
 75
 Rep Power
 0
Ok, I think I get it now.
 04162010, 08:35 PM #8Member
 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.
 04162010, 08:41 PM #9Member
 Join Date
 Feb 2010
 Posts
 75
 Rep Power
 0
No, I get it now. Those are twodimensional 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?
 04162010, 08:55 PM #10
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,017
 Blog Entries
 7
 Rep Power
 23
You always start at the upper left corner of each 2x2 square by using two simple 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
 04162010, 09:06 PM #11Member
 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; 04162010 at 09:10 PM.
 04172010, 02:02 AM #12Member
 Join Date
 Feb 2010
 Posts
 75
 Rep Power
 0
badadabump
 04172010, 08:24 AM #13
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,017
 Blog Entries
 7
 Rep Power
 23
'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
 04172010, 03:43 PM #14Member
 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.
 04172010, 04:30 PM #15
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,017
 Blog Entries
 7
 Rep Power
 23
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: 03222010, 08:17 PM 
Magic Square!!!... :D
By joms999 in forum New To JavaReplies: 4Last Post: 02252010, 08:55 AM 
Magic Eightball
By sachmow in forum New To JavaReplies: 1Last Post: 11152009, 05:37 PM 
help with perfect squares
By AmplifiedKid in forum New To JavaReplies: 1Last Post: 09192009, 07:44 PM 
Perfect Squares
By divyachaparala in forum New To JavaReplies: 4Last Post: 02052008, 10:21 AM
Bookmarks