Berkeley 61A HW3


Feb 26th was a busy day, in fact, I decided to clear all unfinished tasks (Labs, Docs and HWs) before starting Chapter 2 in 61A. However, I underestimate the amount of work involved. Finally, I was only able to complete about half of the tasks that day.

Today I completed that work and started on HW3, which is the final task before Chapter 2.

Question 1 was easy, but I encountered an issue initially – I received a ‘maximum recursion depth exceeded‘ error. This was due to not setting a limit on the scope ( if f>0 ). Eventually, I was able to resolve the issue and complete the task.

My solution
Official solution

Question 2 is harder than Q1, and here is it’s description:

I made a mistake by using too much assignment fuctions, which caused my program to fail the examine program eventhough my testing result was correct.

I am sharing my code for comparison with the official code, which is provide below.

The official code is clearly written and easy to understand the entire function. It seems to be more like recursive function than a regular assignment fuction.

Go on, continue the no.3 question:

I just realize that my ability to design recursive fuctions is very poor, it’s terrible. Although I know how to solve this question, I am unable to finish it with code

Here is my code:

Here is my code and the official solution code, I really need practice my recursive programming skills.

,