import org.apache.log4j.Level;
import org.apache.log4j.Logger;


public class Ackermann {
	
	// Define a static logger variable so that it references the
	// Logger instance named "Ackermann".
	static Logger logger = Logger.getLogger(Ackermann.class);
	static int depth = 0;
	
	static int ack( int m, int n) {
	int ans;
	// logger.debug(String.format("calculating ackerman(%d, %d), depth = %d",m,n,depth));
	depth++;
	if (m == 0) ans = n+1;
	else if (n == 0) ans = ack(m-1,1);
	else ans = ack(m-1, ack(m,n-1));
	depth--;
	return (ans);
	}


	public static void main(String[] args) { int i,j;
	  logger.setLevel(Level.ALL);
	  try {
	    for (i=0; i<6; i++) {
	      for (j=0;j<6; j++) {
            logger.debug(String.format("ackerman (%d,%d) is: %d\n",i,j, ack(i,j)));
	      }
	    }
	  } catch (Exception e) {
		  logger.debug(String.format("Exception at depth=%d",depth));
		  logger.error(e);
	    }
	  }

}
