update UE09_Rekursion2
This commit is contained in:
@@ -10,12 +10,15 @@ public class UE09_Rekursion2 {
|
|||||||
int[][] file1 = readFile("src/UE09_191124_Rekursion2/UE09_triangle1.txt");
|
int[][] file1 = readFile("src/UE09_191124_Rekursion2/UE09_triangle1.txt");
|
||||||
int[][] file2 = readFile("src/UE09_191124_Rekursion2/UE09_triangle2.txt");
|
int[][] file2 = readFile("src/UE09_191124_Rekursion2/UE09_triangle2.txt");
|
||||||
int[][] file3 = readFile("src/UE09_191124_Rekursion2/UE09_triangle.txt");
|
int[][] file3 = readFile("src/UE09_191124_Rekursion2/UE09_triangle.txt");
|
||||||
System.out.println("\n" + maxTotalRekursion(file1, 0, 0));
|
// System.out.println("\n" + maxTotalRekursion(file1, 0, 0));
|
||||||
System.out.println("\n" + maxTotalRekursion(file2, 0, 0));
|
// System.out.println("\n" + maxTotalRekursion(file2, 0, 0));
|
||||||
System.out.println("\n" + maxTotalRekursion(file3, 0, 0)); //Braucht ewig lange, da File sehr groß
|
//// System.out.println("\n" + maxTotalRekursion(file3, 0, 0)); //Braucht ewig lange, da File sehr groß
|
||||||
System.out.println(longestCollatzSequence(999999));
|
// System.out.println("\n" + maxTotal(file1));
|
||||||
System.out.println(longestCollatzSequence(13));
|
// System.out.println("\n" + maxTotal(file2));
|
||||||
System.out.println(collatzSequenceLength(13));
|
// System.out.println("\n" + maxTotal(file3));
|
||||||
|
// System.out.println(longestCollatzSequence(999999));
|
||||||
|
// System.out.println(longestCollatzSequence(13));
|
||||||
|
// System.out.println(collatzSequenceLength(13));
|
||||||
System.out.println(coinSums(2));
|
System.out.println(coinSums(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,10 +37,17 @@ public class UE09_Rekursion2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long maxTotalRekursion(int[][] input, int x, int y) {
|
public static long maxTotalRekursion(int[][] input, int y, int x) {
|
||||||
return (x >= input.length - 1) ? input[x][y] : Long.max(maxTotalRekursion(input, x + 1, y), maxTotalRekursion(input, x + 1, y + 1)) + input[x][y];
|
return (y >= input.length - 1) ? input[y][x] : Long.max(maxTotalRekursion(input, y + 1, x), maxTotalRekursion(input, y + 1, x + 1)) + input[y][x];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long maxTotal(int[][] input) {
|
||||||
|
for (int y = input.length - 1; y >= 0; y--)
|
||||||
|
for (int x = 0; x < input[y].length - 1; x++) input[y - 1][x] += Math.max(input[y][x], input[y][x + 1]);
|
||||||
|
return input[0][0];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static long longestCollatzSequence(int limit) {
|
public static long longestCollatzSequence(int limit) {
|
||||||
long startingNumber = 0, maxLength = 0;
|
long startingNumber = 0, maxLength = 0;
|
||||||
for (int i = 1; i <= limit; i++) {
|
for (int i = 1; i <= limit; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user