Recursive Function With Multiple Constraints

What is the output of the following Python program?

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
def func(a,b):
    if a == 0 and b == 0:
        return 0
    if a == 0: return 1 + func(a,b-1)
    if b == 0: return 1 + func(a-1,b)

    if a > b:
        return 1 + func(func(a-b,b),b-1)
    else:
        return 1 + func(a-1,func(b-a,a))

print func(31415,27182)

Bonus: What is the output of func(a,b) ?

×

Problem Loading...

Note Loading...

Set Loading...