add towers
This commit is contained in:
33
src/UE00_Other/MEDT/SUE/eightTowers.java
Normal file
33
src/UE00_Other/MEDT/SUE/eightTowers.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package UE00_Other.MEDT.SUE;
|
||||
|
||||
public class eightTowers {
|
||||
|
||||
public static final int dim = 8;
|
||||
public static int[] columns = new int[dim];
|
||||
public static boolean[] lines = new boolean[dim];
|
||||
public static int counter = 0;
|
||||
|
||||
public static void main(String[] args) {
|
||||
tower(0);
|
||||
System.out.println(counter);
|
||||
}
|
||||
|
||||
public static void tower(int column) {
|
||||
if (column == dim) {
|
||||
for (int i = 0; i < columns.length; i++) {
|
||||
char c = (char) ('A' + i);
|
||||
System.out.print(c + "" + columns[i] + " ");
|
||||
}
|
||||
System.out.println();
|
||||
counter++;
|
||||
return;
|
||||
}
|
||||
for (int line = 0; line < dim; line++) {
|
||||
if (lines[line]) continue;
|
||||
lines[line] = true;
|
||||
columns[column] = line;
|
||||
tower(column + 1);
|
||||
lines[line] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user