Break the Code

In his dream, Chris coded a recursive function in Python :

1
2
3
4
5
def rec(n):
    if n <= 0:
        return 0

    return 3 + rec(rec(n - _))

Which of the following, when substitute to _ in the 5 th 5^{\text{th}} line will lead to an infinite loop for some integer parameter n n ?

4 3 2

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.

1 solution

Num Ic
Nov 8, 2020

the return value is 3 + something. so i checked what happened if n=3.
_ = 4 will result in return 0 -> no problem
_ = 3 will result in return 0 -> no problem
_ = 2 will again result in return 3+something -> might cause a problem

but big values for n will cause a problem for 3 and 4 too.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...