Calculate Knuth's up arrow notation
Java 7, 121 bytes
int c(int n,int a,int m){return(int)(a<2?Math.pow(n,m):d(n,a));}double d(int n,int a){return Math.pow(n,a<2?n:d(n,a-1));}
Explanation:
int c(int n, int a, int m){ // Main method with the three integer-parameters as specified by OP's challenge
return (int) // Math.pow returns a double, so we cast it to an integer
(a < 2 ? // if (a == 1):
Math.pow(n, m) // Use n^m
: // else (a > 1):
d(n, a)); // Use method d(n, a)
}
double d(int n, int a){ // Method d with two integer-parameters
return Math.pow(n, a < 2 // n ^ X where
? n // X = n if (a == 1)
: d(n, a-1)); // X = recursive call d(n, a-1) if (a > 1)
}
// In pseudo-code:
c(n, a, m){
if a == 1: return n^m
if a > 1: return d(n, a);
}
d(n, a){
if a == 1: return n^n
if a > 1: return d(n, a-1);
}
Test code:
Try it here.
class M{
static int c(int n,int a,int m){return(int)(a<2?Math.pow(n,m):d(n,a));}
static double d(int n,int a){return Math.pow(n,a<2?n:d(n,a-1));}
public static void main(String[] a){
System.out.println(c(2, 1, 2));
System.out.println(c(2, 1, 3));
System.out.println(c(2, 2, 3));
System.out.println(c(2, 3, 3));
}
}
Output:
4
8
16
65536
JavaScript ES7, 53 44 bytes
f=(a,b,c)=>b<2||c<1?a**c:f(a,b-1,f(a,b,c-1))
f=(a,b,c)=>b<2||c<1?a**c:f(a,b-1,f(a,b,c-1))
console.log(f(2,1,2));
console.log(f(2,1,3));
console.log(f(2,2,3));
console.log(f(2,3,3));
Mathematica, 48 40 bytes
If[#3>1<#,#0[#0[#-1,##2],#2,#3-1],#2^#]&
Order of arguments is m, n, a
(using the notation from the challenge).