Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 16 Online
OpenStudy (anonymous):

ps3, problem 2 Hello How to solve problem 2 in ps3 recursively? 2 days are gone and there is no result. I am fascinated with recursion but I gave up. Would you please show the way?

OpenStudy (anonymous):

can you see how this works? http://dpaste.com/693798/

OpenStudy (anonymous):

Hint: All recursive functions follow a typical pattern. First, define the base case. The base case is where the recursion will stop. Second, specify the rule which is followed in each step other than the base case. Below I have defined a recursive function for generating factorials and fibonnaci numbers. The fibonnaci definition is slightly trickier since it requires two base cases. def factorial(n): if n==1: <----base case return n else: <----rule return n * factorial(n-1) print factorial(t) def fib(n): if n==0: <----base case return 0 elif n==1: <----base case return 1 else: return fib(n-1)+fib(n-2) <---rule print fib(t)

OpenStudy (anonymous):

@malpaso I am familiar with concept and these examles. But somehow your explanation gave me energy to give one more try. Thank you. @bwCA. Thank you very much

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!