1
Well, I’m still learning to code in python and I came across exercise that I can’t solve.
I need to write a function that solves Ackermann’s famous function. I think I will not have problems with the syntax and logic behind the function itself, the problem and the calculation. Symbols like "," and "A" itself confuse me. If anyone knows how to solve I would be grateful.
PS: I’m interested in how to solve the function , the python code would be on my own.
A
is the name of the function. IfA
in its definition (body), this means that it will be called recursively in some situations. And the comma simply separates the arguments - this functionA
takes two numbers as argument (here calledm
andn
) and returns a single number, given the definition. Is it clearer? Do you understand what a recursive function is? (whether in mathematics, or in programming)– mgibsonbr
Yes, a recursive function is one that calls itself in the "body" of the function, right ? Yes clarified some doubts , then, if hypothetically I had a group (1,3) the A would be replaced by the same and multiply the sentence between "( )" following ?
– user34098
I don’t understand what you mean. If you have a pair
(1,3)
and wants to apply the functionA
, i and..A(1,3)
, you would be associating to the parameterm
the value1
and the parametern
the value3
. By definition,m = 0
is false andm > 0 and n = 0
is false, so the function value at those points would beA(m - 1, A(m, n - 1))
. Replacing the parameters with their values, we haveA(1 - 1, A(1, 3 - 1))
which is equal toA(0, A(1, 2))
. Then you’d have to calculateA(1, 2)
- by the same process - and use its value to calculateA(0, ...)
- also by the same process.– mgibsonbr
P.S. Please do not use the answer space to comment on the question. You can always comment on your own posts ("comment" link under the question/answers) or - if you have additional information to improve the question - you can also edit the question (link "edit") with this information. I asked a moderator to convert his reply to comment, ok?
– mgibsonbr
Ah yes now I understood :) thank you very much for the help and sorry for the answer, this is my first post and I do not know very well how it works. Thank you very much
– user34098
Oi, Otávio, if you need help in the use of the site, has the support area [meta]. The site has some very specific rules that the [help] clarifies very well, just spend a little time there and then leave for the hug.
– brasofilo