/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package ackerman; /** * * @author suchenek */ /* This is a well tested program that computes one value of 3-argument Ackerman's function. 1st and 2nd argument are the numbers on which a two-argument operation is to be carried out. 3rd argument is an index of the operation. E.g., A(k, m, 0) = k + m A(k, m, 1) = k * m A(k, m, 2) = k ^ m etc. */ public class Ackerman3arg { static long count = 0; public static void main (String [] args) { // int n = Integer.parseInt(args[0]); // int m = Integer.parseInt(args[1]); // int k = Integer.parseInt(args[2]); long n = 2; long m = 2; //second arg of "the" Ackermann's function long k = 3; //first arg of "the" Ackermann's function long a = A(2,m + 2, k - 1) - 3; System.out.print("A(" + n + ", " + m + ", " + k + ") = " + a); System.out.println(" count = " + count); } public static long A(long k, long m, long n) { // count++; if (n == 0) return m + k; else { if (m == 0) { if (n == 1) return 0; else { if (n == 2) return 1; else return k; } } else return A(k, A(k, m-1, n), n-1); } } } /* A(k, m, 0) = m + k; A(k, 0, 1) = 0 A(k, 0, 2) = 1 A(k, 0, n+3) = k A(k, m+1, n+1) = A(k, A(k, m, n+1), n) */ /* Note: "the" Ackermann function (with a simpler recurrence relation) refers to: A(2, n+2, m-1) - 3 */