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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,9 +9,6 @@ import javafx.scene.layout.BorderPane;
|
|||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class UE10_Rekursion3_Aufgabe1 extends Application {
|
public class UE10_Rekursion3_Aufgabe1 extends Application {
|
||||||
|
|
||||||
static final int canvasWidth = 1000;
|
static final int canvasWidth = 1000;
|
||||||
|
|||||||
Reference in New Issue
Block a user