I'm new to python, getting an index error on line 6. what's the deal? trying to create a simple recursion pattern to solve a problem.
Problem// For example, suppose the numbers list were [1, 3, 0, 1]. 0 redirects to 1, who redirects to 3, who redirects back to 1. There is a loop of two : 1, 3. Thus the answer would be 2. Note that even though you started with 0, it is not part of the loop.
some test cases my function must output
Test cases
Inputs: (int list) numbers = [1, 0] Output: (int) 2
Inputs: (int list) numbers = [1, 2, 1] Output: (int) 2
def answer(numbers,depth=0):
if depth > 0:
if depth > numbers:
return false
for m in range(0,depth):
if numbers[m] == numbers[depth]:
return depth+1;
return answer(numbers, depth+1)