update UE09_Rekursion2
This commit is contained in:
@@ -10,16 +10,19 @@ public class UE09_Rekursion2 {
|
||||
int[][] file1 = readFile("src/UE09_191124_Rekursion2/UE09_triangle1.txt");
|
||||
int[][] file2 = readFile("src/UE09_191124_Rekursion2/UE09_triangle2.txt");
|
||||
int[][] file3 = readFile("src/UE09_191124_Rekursion2/UE09_triangle.txt");
|
||||
// System.out.println("\n" + maxTotalRekursion(file1, 0, 0));
|
||||
// System.out.println("\n" + maxTotalRekursion(file2, 0, 0));
|
||||
System.out.println("\n" + maxTotalRekursion(file1, 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" + maxTotal(file1));
|
||||
// System.out.println("\n" + maxTotal(file2));
|
||||
// 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("\n" + maxTotal(file1));
|
||||
System.out.println("\n" + maxTotal(file2));
|
||||
System.out.println("\n" + maxTotal(file3));
|
||||
System.out.println(longestCollatzSequence(999999));
|
||||
System.out.println(longestCollatzSequence(13));
|
||||
System.out.println(collatzSequenceLength(13));
|
||||
int[] coins = new int[]{200, 100, 50, 20, 10, 5, 2, 1};
|
||||
System.out.println(coinSums(200, coins, 0));
|
||||
System.out.println(coinSums(10, new int[]{200, 100, 50, 20, 10, 5, 2, 1}, 0));
|
||||
System.out.println(coinSums(2, new int[]{200, 100, 50, 20, 10, 5, 2, 1}, 0));
|
||||
}
|
||||
|
||||
public static int[][] readFile(String file) {
|
||||
@@ -47,7 +50,6 @@ public class UE09_Rekursion2 {
|
||||
return input[0][0];
|
||||
}
|
||||
|
||||
|
||||
public static long longestCollatzSequence(int limit) {
|
||||
long startingNumber = 0, maxLength = 0;
|
||||
for (int i = 1; i <= limit; i++) {
|
||||
@@ -64,8 +66,9 @@ public class UE09_Rekursion2 {
|
||||
return n == 1 ? 1 : collatzSequenceLength((n & 1) == 0 ? n / 2 : 3 * n + 1) + 1;
|
||||
}
|
||||
|
||||
public static long coinSums(int coin) {
|
||||
System.out.println(coin);
|
||||
return 0;
|
||||
public static int coinSums(int value, int[] coins, int index) {
|
||||
if (value == 0) return 1;
|
||||
if (value < 0 || index >= coins.length) return 0;
|
||||
return coinSums(value - coins[index], coins, index) + coinSums(value, coins, index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user