This question has to do with how to write a recursive function that fits a sequence not printing stars in the form of triangles.
I am trying to write a python function that uses the Pollard Rho method of finding the factorization of an integer. At this point I am stuck on trying to write a small function that will find f(n) such that:
where case 0 through 4 behave like:
I guess I am really confused about how to go about setting up the base case and getting the function to call on itself to calculate the requested iteration of the recursive function. Below is an attempt that doesn't even work for f(0):
def f(xn):
if xn == 0:
answer = 2
return answer
else:
x = xn
f(0) = 2
f(xn) = f(x - 1)^2 + 1
return f(xn)
This attempt simply resulted in an error "SyntaxError: can't assign to function call" when I tried:
print f(0)
Can anyone please help on how to write such a recursive function that matches the behavior of case 0 through 4 as described in the image above my code attempt?