Wikipedia: Ackermann function
I'm writing this program for my computer science class and I don't know why it doesn't work. too be clear, the program works when m <= 3.
I've checked that when m = 4 and n = 1, the result should be 65533 so the variable isn't too small. I've tried using int, long, and double.
public class Recursion {
public static void main(String[] args) {
System.out.print(ack(3, 8));
}
public static long ack(long m, long n) {
if (m == 0) {
return n + 1;
} else if (m > 0 && n == 0) {
return ack(m - 1, 1);
}
return ack(m - 1, ack(m, n - 1));
}
}