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:

i got it all wrong : (

Posted by Chin Loong on October 28, 2001 at 1:47 AM

hey guys, i just remembered an analysis i did long time ago.

then i found out how wrong my "algorithm" or pseudocode was.

there's only 1 IF trial, either the square is *filled* or *empty*.

we just have to imagine that the square is continuous, as in, when u advance rigtht from the right-most column, u'll go back to the left-most column.

so, the new "algorithm" should be :

int n=3;

int square[][]=new int[n][n];
for(int i=0;i for(int j=0;j {
square[i][j]=0; // initialize all to zero
}

int i=(int)(n/2)+1);
int j=0;
square[i][j]=1; // the first one :p

for(int NUMBER=2;NUMBER<=n*n;NUMBER++)
{
i go right;
j go up;

IF square empty
{
square_value=NUMBER;
}
ELSE // if square full
{
go back to previous mode before this, and j go down;
continue;
}
}

*notice* that i took out the codes coz i'm afraid the previous assignment hasn't reached the deadline :p. but if u want to see the codes, just tell me i can either post it up (if other ppl agrees) or i email it to you.

Output results for 5x5 matrix :


Number : 2

00.00.01.00.00.
00.00.00.00.00.
00.00.00.00.00.
00.00.00.00.00.
00.00.00.02.00.


Number : 3

00.00.01.00.00.
00.00.00.00.00.
00.00.00.00.00.
00.00.00.00.03.
00.00.00.02.00.


Number : 4

00.00.01.00.00.
00.00.00.00.00.
04.00.00.00.00.
00.00.00.00.03.
00.00.00.02.00.


Number : 5

00.00.01.00.00.
00.05.00.00.00.
04.00.00.00.00.
00.00.00.00.03.
00.00.00.02.00.


Number : 6

00.00.01.00.00.
00.05.00.00.00.
04.00.00.00.00.
00.00.00.00.03.
00.06.00.02.00.


Number : 7

00.00.01.00.00.
00.05.00.00.00.
04.00.00.00.00.
00.00.07.00.03.
00.06.00.02.00.


Number : 8

00.00.01.00.00.
00.05.00.00.00.
04.00.00.08.00.
00.00.07.00.03.
00.06.00.02.00.


Number : 9

00.00.01.00.00.
00.05.00.00.09.
04.00.00.08.00.
00.00.07.00.03.
00.06.00.02.00.


Number : 10

10.00.01.00.00.
00.05.00.00.09.
04.00.00.08.00.
00.00.07.00.03.
00.06.00.02.00.


Number : 11

10.00.01.00.00.
00.05.00.00.09.
04.00.00.08.00.
11.00.07.00.03.
00.06.00.02.00.


Number : 12

10.00.01.00.00.
00.05.00.00.09.
04.12.00.08.00.
11.00.07.00.03.
00.06.00.02.00.


Number : 13

10.00.01.00.00.
00.05.13.00.09.
04.12.00.08.00.
11.00.07.00.03.
00.06.00.02.00.


Number : 14

10.00.01.14.00.
00.05.13.00.09.
04.12.00.08.00.
11.00.07.00.03.
00.06.00.02.00.


Number : 15

10.00.01.14.00.
00.05.13.00.09.
04.12.00.08.00.
11.00.07.00.03.
00.06.00.02.15.


Number : 16

10.00.01.14.00.
00.05.13.00.09.
04.12.00.08.16.
11.00.07.00.03.
00.06.00.02.15.


Number : 17

10.00.01.14.00.
17.05.13.00.09.
04.12.00.08.16.
11.00.07.00.03.
00.06.00.02.15.


Number : 18

10.18.01.14.00.
17.05.13.00.09.
04.12.00.08.16.
11.00.07.00.03.
00.06.00.02.15.


Number : 19

10.18.01.14.00.
17.05.13.00.09.
04.12.00.08.16.
11.00.07.00.03.
00.06.19.02.15.


Number : 20

10.18.01.14.00.
17.05.13.00.09.
04.12.00.08.16.
11.00.07.20.03.
00.06.19.02.15.


Number : 21

10.18.01.14.00.
17.05.13.21.09.
04.12.00.08.16.
11.00.07.20.03.
00.06.19.02.15.


Number : 22

10.18.01.14.22.
17.05.13.21.09.
04.12.00.08.16.
11.00.07.20.03.
00.06.19.02.15.


Number : 23

10.18.01.14.22.
17.05.13.21.09.
04.12.00.08.16.
11.00.07.20.03.
23.06.19.02.15.


Number : 24

10.18.01.14.22.
17.05.13.21.09.
04.12.00.08.16.
11.24.07.20.03.
23.06.19.02.15.


Number : 25

10.18.01.14.22.
17.05.13.21.09.
04.12.25.08.16.
11.24.07.20.03.
23.06.19.02.15.
Process Exit...




Replies:

Sponsored Links



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