CS61A HOMEWORK 8 SOLUTIONS

Therefore, even if c returns False , the function t will be called. Write a procedure substitute that takes three arguments: Find duplicates k More Review: If you are having a hard time identifying how the if statement and if function differ, first try to get them to print out different values. We choose the operator add or sub based on the sign of b. You may check the solutions if you are stuck, but we highly recommend you work through the problem on your own for practice. Define a function that returns a stream of random numbers that uses this linear-congruential formula.

If you have any questions about using OK, please refer to this guide. Missing Value Question 2: Likewise, any lambda expressions should contain only calls to these functions. Implement derive-sum , a procedure that differentiates a sum by summing the derivatives of the addend and augend. Write a function that takes three positive numbers and returns the sum of the squares of the two largest numbers. Write a function that takes an integer n that is greater than 1 and returns the largest integer that is smaller than n and evenly divides n. These are called regular numbers.

Homework 1 Solutions | CS 61A Summer

If you have any questions about using OK, please refer to this guide. Implement derive-suma procedure that differentiates a sum by summing the derivatives of the addend and augend.

This is guaranteed to be the largest factor of n. Implement derive-productwhich applies the product rule to differentiate products:. The built-in procedure expt takes two number arguments and raises the first to the power of the second. Write a procedure substitute that takes three arguments: Use data abstraction for a sum:.

  DISSERTATION ZADIG CHAPITRE 3

Homework Questions

You can simplify the cases when exponent is 0 or 1 soutions, or when base is a number, by returning numbers from the constructor make-exp. Therefore, even if c returns Falsethe function t will be called.

cs61a homework 8 solutions

Likewise, any lambda expressions should contain only calls to these functions. This sequence of values of n is often called a Hailstone sequence, Write a function that takes a single argument with formal parameter name nprints out the hpmework sequence starting at nand returns the number of steps in the sequence:. As an alternative, we can build a stream of such numbers. A common method of producing pseudo-random numbers is by means of the following recurrence relation:.

But this is very inefficient, since, as the integers get larger, fewer and fewer of them fit the requirement. Sums and products are lists, and they are simplified on construction:. Use only a single hhomework for the body of homesork function. Write sub-allwhich takes a list sa list of old words, and a list of new words; the last two lists must be the same length.

Stream of Streams Differentiation Question 9: Analogously, a hailstone travels up and down in the atmosphere before eventually landing on earth. The number n will travel up and down but eventually end at 1 at least for all numbers that have ever been tried — nobody has ever proved that the sequence will terminate.

  GD GOENKA ROHINI SEC 9 HOLIDAY HOMEWORK 2015

Scale Stream Question 6: These are called regular numbers. Missing Value Question 2: Regular Numbers Question 7: You may submit more than once before the deadline; only the final submission will be scored.

cs61a homework 8 solutions

Despite the doctests above, this function actually does not do the same thing as an if statement in all cases. Make Exp Question For this we define a merge function that combines two ordered streams into one ordered result stream, eliminating repetitions. Fill in the blanks in the following function definition for adding a to the absolute value of bwithout calling abs.

You might find the following references useful:. It was one of the motivating examples behind the development of the language. The derive Scheme procedure takes an algebraic expression and a variable and returns the derivative of the expression with respect to the variable. Derive Sum Question It returns vs61a list with the elements of sbut with every occurrence of old replaced by neweven within sub-lists.

cs61a homework 8 solutions

Implement derive-expwhich uses the power rule to derive exps:.