In this prelab you will formulate some of the ideas necessary to complete Lab 06. Please type your solutions, and hand in a paper copy before the beginning of class on Wednesday. Remember, no late prelabs allowed!
Read this Scientific American article about how diversity makes us smarter. If you're so inclined, you should also check out the following two embarrassing examples of what can happen when your development and testing teams aren't diverse: Exhibit A and Exhibit B.
For the following two problems, you'll work out by hand the result of method invocations of the following two recursive methods.
def strange(x) : if x <= 0 : return 1 else : return 5 * strange(x-1) - 2
def weird(x) : if x > 0 : print(x,"",end='') if x%2 == 0 : weird(x-3) weird(x-2) else : weird(x-1)
As we have seen (or will have seen, depending on when you're looking at this), the factorial function can be computed not only using a loop, but via recursion as well. Recall the the typical definition of factorial looks something like this: 0! = 1, 1! = 1, 2! = 2*1 = 2 and 3! = 3*2*1 = 6, and in general, n! = n*(n-1)*...*3*2*1.
But we could also define the factorial function recursively as follows. We'll use fact(n) to denote our recursive representation of n!. We'll define fact(n) = 1 when n is 0 and fact(n) = n*fact(n-1) otherwise. If you think about it, fact(n) gives the exact same values as n!.
Here is pseudocode for recursively printing a string s in reverse
If the length of s is 0, do nothing Otherwise, print the last letter of s and reverse s with the last letter removed.
Consider the following figure.
Let Ax and Ay denote the x and y coordinates of the corner labelled A in the large triangle above. Let Bx, By, Cx and Cy be definied similarly. Assume P, Q and R each lie at the midpoint of their corresponding edge in the triangle ABC.
If you followed the Honor Code in this assignment, write the following sentence attesting to the fact at the top of your homework.
I affirm that I have adhered to the Honor Code in this assignment.