8queen

Terminal Transcript @ Sep 3, 2012 4:33:01 PM

1 public class EightQueens
2 {
3 private static final int COL = 8;
4
5 static char[] arrChar = new char[3];
1 public class EightQueens
2 {
3 private static final int COL = 8;
4
5 static char[] arrChar = new char[3];
6
7 public static void anagram( int size )
8 {
9 if( size == 1 )
10 {
11 return;
12 }
13 for( int i = 0; i < size; i++ )
14 {
15 anagram( size – 1 );
16 if( size == 2 )
17 {
18 display( );
19 }
20 rotate( size );
21 }
1 public class EightQueens
2 {
3 private static final int COL = 8;
4
5 static char[] arrChar = new char[3];
6
7 public static void anagram( int size )
8 {
9 if( size == 1 )
10 {
11 return;
12 }
13 for( int i = 0; i < size; i++ )
14 {
15 anagram( size – 1 );
16 if( size == 2 )
17 {
18 display( );
19 }
20 rotate( size );
21 }
1 public class EightQueens
2 {
3 private static final int COL = 8;
4
5 static char[] arrChar = new char[3];
6
7 public static void anagram( int size )
8 {
9 if( size == 1 )
10 {
11 return;
12 }
13 for( int i = 0; i < size; i++ )
14 {
15 anagram( size – 1 );
16 if( size == 2 )
17 {
18 display( );
19 }
20 rotate( size );
21 }
22 }
1 public class EightQueens
2 {
3 private static final int COL = 8;
4
5 static char[] arrChar = new char[3];
6
7 public static void anagram( int size )
8 {
9 if( size == 1 )
10 {
11 return;
12 }
13 for( int i = 0; i < size; i++ )
14 {
15 anagram( size – 1 );
16 if( size == 2 )
17 {
18 display( );
19 }
20 rotate( size );
21 }
22 }
22 }
23
24 public static void rotate( int size )
22 }
23
24 public static void rotate( int size )
11 return;
12 }
13 for( int i = 0; i < size; i++ )
14 {
15 anagram( size – 1 );
16 if( size == 2 )
17 {
18 display( );
19 }
20 rotate( size );
21 }
22 }
23
24 public static void rotate( int size )
1 public class EightQueens
2 {
3 private static final int COL = 8;
4
5 static char[] arrChar = new char[3];
6
7 public static void anagram( int size )
8 {
9 if( size == 1 )
8 {
9 if( size == 1 )
10 {
2 {
3 private static final int COL = 8;
4
5 static char[] arrChar = new char[3];
6
7 public static void anagram( int size )
8 {
9 if( size == 1 )
10 {
11 return;
6
7 public static void anagram( int size )
8 {
9 if( size == 1 )
10 {
11 return;
12 }
13 for( int i = 0; i < size; i++ )
1 public class EightQueens
2 {
3 private static final int COL = 8;
4
5 static char[] arrChar = new char[8];
6
7 public static void anagram( int size )
8 {
9 if( size == 1 )
10 {
11 return;
12 }
13 for( int i = 0; i < size; i++ )
14 {
15 anagram( size – 1 );
16 if( size == 2 )
17 {
18 display( );
19 }
20 rotate( size );
21 }
22 }
23
24 public static void rotate( int size )
25 {
26 int pos = COL – size;
1 public class EightQueens
2 {
19 }
20 rotate( size );
21 }
22 }
23
24 public static void rotate( int size )
1 public class EightQueens
2 {
3 private static final int COL = 8;
4
5 static int[] arrInt = new int[8];
6
7 public static void anagram( int size )
8 {
9 if( size == 1 )
10 {
11 return;
12 }
13 for( int i = 0; i < size; i++ )
14 {
15 anagram( size – 1 );
16 if( size == 2 )
17 {
18 display( );
19 }
20 rotate( size );
21 }
22 }
23
24 public static void rotate( int size )
25 {
26 int pos = COL – size;
27 int temp = arrInt[pos];
1 public class EightQueens
2 {
3 private static final int COL = 8;
4
5 static int[] arrInt = new int[8];
6
7 public static void anagram( int size )
8 {
9 if( size == 1 )
10 {
11 return;
12 }
13 for( int i = 0; i < size; i++ )
14 {
15 anagram( size – 1 );
16 if( size == 2 )
17 {
18 display( );
19 }
20 rotate( size );
21 }
22 }
23
24 public static void rotate( int size )
25 {
26 int pos = COL – size;
27 int temp = arrInt[pos];
28 for( int i = pos + 1; i < COL; i++ )
29 {
30 arrInt[i-1] = arrInt[i];
31 }
32 arrInt[COL-1] = temp;
33 }
34
35 public static void display( )
36 {
37 for(int i = 0; i < COL; i++)
38 {
39 for( int j = i+1; j < COL;j++ )
40 {
41 if( ( i – j == arrInt[i] – arrInt[j] ) && ( j – i == arrInt[j] – arr[i]) )
42 {
43 return;
44 }
45 }
46 System.out.print( arrInt[i] + " " );
47 }
48 System.out.println( "" );
49 }
50
51 public static void main( String[] args )
52 {
53 for( int i = 0; i < 8; i++ )
EightQueens.java 45,4-13 78%
"EightQueens.java" 60L, 930C written

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s