3 Replies Latest reply: Apr 3, 2010 11:14 AM by 843853 RSS

    Magic Square Algorithm

    843853
      I posted this question on Ubuntu forums but it was closed because it's part of the code of conduct over there to not ask for homework help so I made an account here. So here is the question: http://ubuntuforums.org/showthread.php?t=1445529

      Someone gave me an answer that works but I would appreciate it if someone could help me understand because I don't just want to blindly copy that code. In fact, I'd like to implement it myself but I'd like to know:

      1) What his or her code does exactly that makes it work
      2) What my code was doing wrong

      Any input would be greatly appreciated!
      Thanks in advance!
        • 1. Re: Magic Square Algorithm
          jwenting
          And why do you think we're going to do your homework for you? Get lost, lazy kiddo.
          • 2. Re: Magic Square Algorithm
            843853
            I already have "the answer." So technically, right now all I am asking is to just get help to understand what I was doing wrong and what the other guy did right ... that sounds pretty legitimate to me.

            (If this is not a homework helping forum then what is? I'm actually asking because I have math & physics homework help forums with people helping for example but in programming people tend to reject me)

            Edited by: s3a on 3-Apr-2010 10:53 AM
            • 3. Re: Magic Square Algorithm
              843853
              If there is someone out there that will answer me: I'm still analyzing and trying to reproduce the code without looking at it but I don't understand why there is a row = row + 2; in the code that guy gave me in the other forum.

              I thought that when a position of the magic square is not taken (== 0 in the component of the array) that you would just add 1 to the row but do nothing to the column, instead I see that the guy did:
              row =+ 2;
              column--;
              and apart from the two System.out.println(); lines of his code, it's all good.

              Edit: Also another thing I realized is when my teacher showed us how a magic square works, he showed us that you go up 1 and right 1 but if you're adding to the rows component of the array then aren't you going down? Also, if you're subtracting from column, aren't you going left instead of right?

              Edited by: s3a on 3-Apr-2010 12:13 PM