The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
October 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

argh ~~

Posted by Chin Loong on October 26, 2001 at 5:02 AM

dang... they don't capture the spaces >,<

#assuming left-bottom most square is (0,0) and coord <=> (i,j)

1. i don't know why but i always start with the top row of the matrix, in the middle. place "1" there. ((int)(i_max/2)+1),j_max)

2. head north-east. (i+1,j+1)

for(int NUMBER=2;NUMBER<=nxn;NUMBER++)
{
....IF it's a valid square (inside the matrix and empty)
....{
........place the NUMBER there.
....}
....ELSE (it's not a valid square)
....{
........IF it's outside the matrix
........{
............IF the destination column (i+1) is valid (inside matrix)
............{
................place the NUMBER at the bottom of the column (i+1,j_min)
............}
............ELSE IF the destination row (j+1) is valid (inside matrix)
............{
................place the next number at the left end of the row (i_min,j+1)
............}
............ELSE IF both the column and row not valid - outside matrix)
............{
................go down one square (i,j-1) and place the NUMBER there
............}
........}
........ELSE (if not invalid square, must be non-empty square)
........{
............go down one square (i,j-1) and place the NUMBER there
........}
....}
}




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us