Exercise 11.4 ThinkJulia

here’s the text of the exercise:
Memoize the Ackermann function and see if memoization makes it possible to evaluate the function with bigger arguments.
I understand what memoization is, and i did with the fibonacci serie. I can’t understand how can i do it with the Ackermann function since it has two arguments , and not only one as the fibonacci serie.

1 Like

Is that book advising to use Memoize.jl or something else?

@memoize can handle multiple arguments

no, he’s not advising to use that package.

Can you show your fibonacci solution? Then it’s easier for people here on the forum to expand on that for ackerman

A two-argument function is (conceptually) the same as a function with a single argument, a tuple of 2 numbers. You can memoize by doing whatever you did for one-parameter functions, but using (x, y) as your key.

known = Dict(0=>0, 1=>1)

function fibonacci(n)
    if n ∈ keys(known)
        return known[n]
    res = fibonacci(n-1) + fibonacci(n-2)
    known[n] = res

that’s the fibonacci using memoization