/* * Ackerman.java * * Created on March 20, 2008, 7:53 AM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package ackerman; /** * * @author suchenek */ //Copyright Dr. Marek Suchenek 2000 through 2025 public class Ackerman { static long count = 0; public static void main (String [] args) { int n = 4; //Integer.parseInt(args[0]); int lim = 4; //Integer.parseInt(args[1]); for (int m = 0; m <= lim; m++) { long a; count = 0; try { a = A(n,m); System.out.print("a(" + n + ", " + m + ") = " + a); } catch(StackOverflowError e) { double aa = Double.POSITIVE_INFINITY; System.out.print("a(" + n + ", " + m + ") = " + aa); } System.out.println(" count = " + count); } } public static long A(long n, long m) { count++; if (n == 0) return m + 1; else { if (m == 0) return A(n-1, 1); else return A(n-1, A(n, m-1)); } } }