Tutor profile: William Z.
Subject: Python Programming
Create a python program that reverses a linked list.
def reverse(list): list.prev = None list.current = list.head while(list.current is not None): list.next = list.current.next list.current.next = list.prev list.prev = list.current list.current = list.next list.head = list.prev This program recursively loops through a linked list, continually moving the front of the linked list to the back, until the end of the list is at the front of the list.
A window is being built and the bottom is a rectangle and the top is a semicircle. If there is 12 meters of framing materials what must the dimensions of the window be to let in the most light?
Basically, this question is asking you to maximize the area of the window so that it is able to receive the most light. Now, we know that the area of the rectangle is width * height, and the area of the circle is pi*radius^2 (For those that did not know, ^2 denotes the preceding number to the power of 2. In an optimization problem, we have a equation to optimize and a constraint equation. Our constraint is that the perimeter of our window must be 12 meters long and we are attempting to maximize the area. Now, note that the width of the rectangle is equal to the diameter of the semicircle. We denote the radius of the circle as r. Now, the circumference of a circle is 2*pi*r, so that of a semicircle is pi*r. The perimeter of the rest of the window is 2r (width) + 2*L (length of the rectangle). Note that we did not use the standard perimeter of rectangles because one of the sides is not included. We have now derived our constraint equation 12 = pi*r + 2*r + 2*L. Now, we must find the equation we are aiming to optimize. Since the area of a circle is pi*r^2, then the area of a semicircle is (1/2)*pi*r^2. The area of the square portion is 2r (width) * 2L (length). Thus, putting all of those components together, we have our optimization equation, A = (1/2)*pi*r^2 + 2r * 2L. So, we solve the constraint for L and plug it into the optimization equation: 2L = 12 - pi*r - 2r L = 6 - 0.5pi*r - r So, A = 0.5pi*r^2 + 2r * (6 - 0.5pi*r - r). Simplifying, A = -0.5pi*r^2 + 12r + 2r^2 Taking the first derivative, A' = -pi*r + 12 - 4r Taking the second derivative, A'' = -pi - 4. Plugging in 0 for A', we have the critical point r = 12/(4 + pi). We can also see that the second derivative is always negative, which means our critical point must denote a maximum. So, plugging our critical point back into the original equation, we will get the optimal radius of 1.6803 and an optimal rectangle dimension of 3.3606 * 1.6803.
You collect stamps. John decides to quadruple your stamps. Pearl gives you another 8 stamps. Miguel gives you another 22 stamps. Since you're nice, you give Sharon 80 stamps. Jose gives you another 10 stamps. At the end you have 60. How many stamps did you start with?
Since you ended up with 60 stamps, you had 60-10 = 50 stamps before Jose gave you 10 stamps. Then, since you gave Sharon 80 stamps, that means you had 50 + 80 = 130 stamps before you gave Sharon the stamps. Therefore, before Miguel gave you 22 stamps, you had 130 - 22 = 108 stamps, and before Pearl gave you 8 stamps, you had 108-8 = 100 stamps. Now, since John quadrupled the number of stamps you had, that means you started out with 100/4 = 25 stamps.
needs and William will reply soon.