Sub All Streams Question 5: Implement a data abstraction for exponentiation: Some of the problems use a utility method called timeit , which takes a parameterless function as argument, executes it, and returns the time required to do so. You may submit more than once before the deadline; only the final submission will be scored. Define a function that returns a stream of random numbers that uses this linear-congruential formula. Check that you have successfully submitted your code on okpy.
Stream of Streams Differentiation Question 9: Fill in the blanks in the following function definition for adding a to the absolute value of b , without calling abs. Symbolic differentiation is of special historical significance in Lisp. We choose the operator add or sub based on the sign of b. Make Exp Question The max function can take an arbitrary number of arguments.
So, we can take the max of the sum of squares of all pairs. Stream of Streams Differentiation Question 9: Scale Stream Question 6: You hkmework submit more than once before the deadline; only the final submission will be scored.
Linear Congruential Generator Extra questions Question 8: This sequence of values of n hpmework often called a Hailstone sequence, Write a function that takes a single argument with formal parameter name nprints out the hailstone sequence starting at nand returns the number of steps in the sequence:.
We choose the operator add or sub based on the sign of b. Implement a data abstraction for exponentiation: A common method of producing pseudo-random numbers is by means of the following recurrence relation:.
Sub All Streams Question 5: Fill in the blanks in the following function definition for adding a to the absolute value of bwithout calling abs. Implement derive-suma procedure that differentiates a sum by summing the derivatives of the addend and augend. The following problems develop a system for symbolic differentiation of algebraic expressions. The base can be any expression, but assume that the exponent is a non-negative integer.
A famous problem, first raised by Richard Hamming, is to enumerate, in ascending order with no repetitions, all positive integers with no prime factors other than 2, 3, or 5. Iterating from n-1 to 1, we return the cs16a integer that evenly divides n.
Define a function that returns a stream of random numbers that uses this linear-congruential formula. Differentiating is a recursive process that applies different rules to different kinds of expressions:.
As an alternative, we can build a stream of such numbers. You may check the solutions if you are stuck, but we highly recommend you work through the problem on your own for practice.
Check that you have successfully submitted your code on okpy. One obvious way to do this is to simply test each integer in turn to see whether it has any factors other than 2, 3, and 5. The number n will travel up and down but eventually end at 1 at least for cs61x numbers that have ever been tried — nobody has ever proved that the sequence will terminate.
The derive Scheme procedure takes an algebraic expression and a variable and returns the derivative of the expression with respect to the variable.
Cw61a max function can take an arbitrary number of arguments. You can simplify the cases when exponent is 0 or 1or when base is a number, by returning numbers from the constructor make-exp. Sums and products are lists, and they are simplified on construction:.
Homework Questions Some Review: Derive Sum Question Write a function that takes three positive numbers and returns the sum of the squares of the two largest numbers. This is guaranteed to be the largest solufions of n.
For this we define a merge function that combines two ordered streams into one ordered result stream, eliminating repetitions. When you are done, submit with python3 ok –submit. To implement the system, we will use the following data abstraction. Make Exp Question