The Ackermann function is a computable function which grows very, very quickly as its inputs grow. For example, while
A
(
1
,
2
)
,
A
(
2
,
2
)
,
and
A
(
3
,
2
)
are equal to
4
,
7
,
and
2
9
,
respectively,
A
(
4
,
2
)
≈
2
×
1
0
1
9
7
2
8
.
The Ackermann function can be defined as follows: A ( m , n ) = ⎩ ⎪ ⎨ ⎪ ⎧ n + 1 A ( m − 1 , 1 ) A ( m − 1 , A ( m , n − 1 ) ) if m = 0 if m > 0 and n = 0 if m > 0 and n > 0 .
What is the value of A ( 0 , 7 ) ?
Details and assumptions
If you enjoyed this problem, you might also like Part 2 and Part 3 .
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
A(0,7) = 7+1 = 8;
very nice
its a quit simple recursive function
7 + 1 = 8
m==0 is true this implies A(0,7) should return n+1 ie 7+1 = 8
m=0 , value of A(0,7)=n+1; so 7+1=8,,
i don't understad how to get that aswer explain it in an easy way
Log in to reply
in the question if m=0, A(m,n)=n+1 , so its A(0,7) n=7 , A(0,7)=7+1=8
Since A(0,n) = A(m,n) when m=0, and n=7, and A(m,n) when m=0 is n+1, and since n=7, the answer is 8.
Turbo C++ code for this problem and it also works for part 2 of this problem if you change the parameters of the function A to (3,6) in the line tot=A(0,7).
#include<iostream.h>
#include<conio.h>
long A(int,int);
void main()
{
int tot;
clrscr();
tot=A(0,7);
cout<<endl<<tot;
getch();
}
long A(int m, int n)
{
long ret=0;
if(m==0)
{
ret=n+1;
return ret;
}
if(m>0 && n==0)
{
ret=A(m-1,1);
return ret;
}
if(m>0 && n>0)
{
ret=A(m-1,A(m,n-1));
return ret;
}
}
NICELY SOLVED USING C++
8
by C++ easy solveable
public static int ACC(int m, int n) {
int ans=0;
if(m==0){
ans=n+1;
}
else if(n==0 && m>0){
ans = ACC(m-1,1);
}
else if(m>0 && n>0){
ans = ACC(m-1, ACC(m,n-1));
}
return ans;
}
public static void main(String[] args){
System.out.print(Check.ACC(3, 6));
}
}
509
Check.ACC(3, 6) ??? I'm new to Java ,,, I got alot of learning to do ,,
Log in to reply
Check is a class which contains method(Function) ACC if method is qualified by "static" you can call it by using a dot after class name followed by method name and input arguments
<className> . <Methodname>( input arguments) so to call the ACC method of check class Check . ACC(3,6) :)
Log in to reply
It's the calling of a method within itself that I do not get ,,,, but I get it now ,,,
Python Solution:
def A(m, n):
if m == 0:
return n+1
elif m > 0 and n == 0:
return A(m-1, 1)
else:
return A(m-1, A(m, n-1))
>>> 8
(waiting for Part 2 and 3...)
Also, because m = 0 , you can just use the first case of the function to get 7 + 1 = 8
I still don't get part 2 and 3 please can anyone explain this in a easy way
given A(0,7) where m=0 and n=7 A/C to condition if m=0; then A(m,n)=n+1 i.e A(m,n)=7+1=8
as in problem we have to find the value of(0,7) according to acekman function m=0 n=7 so value will be n+1=8
Minified function (with Google Closure Compiler) # function A(a, b) { return 0 === a ? b + 1 : 0 < a && 0 === b ? A(a - 1, 1) : A(a - 1, A(a, b - 1)); };
Normal function # function A(m, n) { if (m === 0) return n + 1; else if (m > 0 && n === 0) return A(m - 1, 1); else return A(m - 1, A(m, n - 1)); };
A(m,n) = A(0,7) Beause and it says when m=0, then n+1 so 8 is answer
int recu(int a,int b) if(a==0) return b+1; else if(a>0&&b==0) return recu(a-1,1); else return recur(a-1,recur(a,b-1));
because m = 0, then A(m,n) = n + 1 = 7 + 1 =8
A(m,n)=A(0,7) m-0,then n+1, 7+1=8
A(0,0) =1 A(0,1)=2 . . A(0,7)=8
In general, A(0,n) = n+1
From the function given, if m=0,then solution is n+1
As it was given, if m=0, then A(m,n)=n+1, thus A(0,7)=7+1=8 =)
m=0 so we will use n+1 and that is equal to 7+1=8
8 because a(m,n)= n+1 since m=0 and here n =7 the ans is n+1=7+1=8
in A(0,7) the value of m is 0 if we compare it with A(m,n). and the value of n is 7 so according to the ackermann function if m=0 then A(m,n)=n+1 which leads to A(0,7)=8 hence 8 is the answer.
8
A ( m , n ) = A ( 0 , 7 )
m = 0
A ( m , n ) = n + 1
8
Problem Loading...
Note Loading...
Set Loading...
This was rather easy,but I suspect Parts 2 and 3 will be significantly more difficult. Anyways,there are more efficient approaches but a naive recursive function will do for this problem..
8