Upload files to "VL5"

This commit is contained in:
i23016 2023-12-04 17:11:47 +00:00
parent b2e943e87b
commit a07f491977
4 changed files with 134 additions and 0 deletions

39
VL5/Aufgabe1.java Normal file
View File

@ -0,0 +1,39 @@
/*
* Author: Oliver Ilczuk
* Fach : Programmieren
* fibonacci_iterativ laeuft viel schneller, da die Werte direkt in Variablen gespeichert
* und nicht rekursiv im Stack abgelaufen werden.
*/
public class Aufgabe1 {
public static void main(String[] args){
fibonacci_iterativ(45);
System.out.println("----////////////----");
init_fib_rec(45);
}
public static void fibonacci_iterativ(int fib){
int buffErg1 = 0;
int buffErg2 = 1;
System.out.println(buffErg1 + ", ");
System.out.println(buffErg2 + ", ");
for(int i=1; i<fib; i++){
int ErgNext = buffErg1 + buffErg2;
buffErg1 = buffErg2;
buffErg2 = ErgNext;
System.out.println(ErgNext + ", ");
}
}
public static void init_fib_rec(int fib){
for (int i = 0; i <= fib; ++i) {
System.out.println("i: " + i + " = " + fibonacci_recursive(i) + ", ");
}
}
public static int fibonacci_recursive(int fib){
if (fib <= 1) {
return fib;
} else {
return fibonacci_recursive(fib - 1) + fibonacci_recursive(fib - 2);
}
}
}

55
VL5/Aufgabe2.java Normal file
View File

@ -0,0 +1,55 @@
/*
* Author: ChatGPT
* Fach : Programmieren
* Wie unter Author erwaehnt, diese Loesung wurde nicht von mir geschrieben,
* da ich das Problem nicht vollstaendig loesen konnte und selbst meine Ansaetze
* fehlerhaft waren.
*/
public class Aufgabe2 {
public static void main(String[] args) {
solveEightQueens();
}
public static void solveEightQueens() {
int[] queens = new int[8];
placeQueens(queens, 0);
}
private static void placeQueens(int[] queens, int row) {
if (row == 8) {
printSolution(queens);
return;
}
for (int col = 0; col < 8; col++) {
if (isSafe(queens, row, col)) {
queens[row] = col;
placeQueens(queens, row + 1);
}
}
}
private static boolean isSafe(int[] queens, int row, int col) {
for (int i = 0; i < row; i++) {
if (queens[i] == col || queens[i] - i == col - row || queens[i] + i == col + row) {
return false;
}
}
return true;
}
private static void printSolution(int[] queens) {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (queens[i] == j) {
System.out.print("Q ");
} else {
System.out.print(". ");
}
}
System.out.println();
}
System.out.println();
}
}

29
VL5/Aufgabe3.java Normal file
View File

@ -0,0 +1,29 @@
import java.io.FileWriter;
import java.io.IOException;
public class Aufgabe3 {
static FileWriter logFile;
//int i = 0;
public static void main(String[] args){
try{
logFile = new FileWriter("log_stack.txt", true);
//logFile.close();
} catch (IOException e){
System.out.println("An error occurred.");
e.printStackTrace();
}
stackFiller(0);
}
public static void stackFiller(int j){
int i = j;
try{
logFile.write(i + ", ");
stackFiller(i+1);
}catch (IOException e){
System.out.println("An error occurred.");
e.printStackTrace();
}
}
}

11
VL5/log_stack_Result.txt Normal file
View File

@ -0,0 +1,11 @@
default stack: 2915
256k : 1549
512k : 1549
1m : 2915
2m : 7011
4m : 13289
8m : 24992
16m : 49568
32m : 99773
64m : 410074
128m : 1227509