Hier ist mein Code und im Anhang ist die Aufgabe Stellung. Es wäre cool, wenn ihr mir helfen könnt. Danke !
Java:
public static long waysHome(int length, int x, int y) {
if (x == length && y == 0) { // Base case: reached the end
return 1;
} else if (x > length || y < 0 || y > (length - x)) { // Edge case: exceeded the boundary
return 0;
} else {
// Recursive case: count the number of ways to reach the end by going right and swaying left or right
return waysHome(length, x + 1, y) + waysHome(length, x + 1, y + 1) + waysHome(length, x + 1, y - 1);
}
}