Hw05 cs61a

Download hw The vitamin problems can be found in the vitamin directory and the homework problems can be found in the problems directory.

You must run python3 ok --submit twice: once inside the vitamin directory, and once inside the problems directory. Submission: When you are done, submit with python3 ok --submit. You may submit more than once before the deadline; only the final submission will be scored.

Check that you have successfully submitted your code on okpy. See Lab 0 for more instructions on submitting assignments. Readings: You might find the following references useful:. A classic puzzle called the Towers of Hanoi is a game that consists of three rods, and a number of disks of different sizes which can slide onto any rod.

The puzzle starts with n disks in a neat stack in ascending order of size on a start rod, the smallest at the top, forming a conical shape. The objective of the puzzle is to move the entire stack to an end rod, obeying the python ping a hostname rules:. This interval arithmetic example is based on a classic problem from Structure and Interpretation of Computer Programs, Section 2.

Alyssa P. Hacker is designing a system to help people solve engineering problems. One feature she wants to provide in her system is the ability to manipulate inexact quantities such as measured parameters of physical devices with known precision, so that when computations are done with such approximate quantities the results will be numbers of known precision.

Alyssa's idea is to implement interval arithmetic as a set of arithmetic operations for combining "intervals" objects that represent the range of possible values of an inexact quantity. The result of adding, subracting, multiplying, or dividing two intervals is itself an interval, representing the range of the result.

Alyssa postulates the existence of an abstract object called an "interval" that has two endpoints: a lower bound and an upper bound. She also presumes that, given the endpoints of an interval, she can construct the interval using the data constructor interval. Using the constructor and selectors, she defines the following operations:. Alyssa's program is incomplete because she has not specified the implementation of the interval abstraction. She has implemented the constructor for you; fill in the implementation of the selectors.

Louis Reasoner has also provided an implementation of interval multiplication. Beware: there are some data abstraction violations, so help him fix his code before someone sets it on fire. Using reasoning analogous to Alyssa's, define a subtraction function for intervals. Try to reuse functions that have already been implemented. Alyssa implements division below by multiplying by the reciprocal of y. Ben Bitdiddle, an expert systems programmer, looks over Alyssa's shoulder and comments that it is not clear what it means to divide by an interval that spans zero.

Add an assert statement to Alyssa's code to ensure that no such interval is used as a divisor:. After considerable work, Alyssa P. Hacker delivers her finished system. Several years later, after she has forgotten all about it, she gets a frenzied call from an irate user, Lem E. It seems that Lem has noticed that the formula for parallel resistors can be written in two algebraically equivalent ways:.

Lem complains that Alyssa's program gives different answers for the two ways of computing. This is a serious complaint. Demonstrate that Lem is right.The final exam will be replaced by 3 minute in-lecture exams. The Midterm 1 exam and solution are posted. Week 13 Class Material. Week 13 Resources. Week 12 Class Material.

Week 12 Resources. Week 11 Class Material. Week 11 Resources. Week 9 Class Material. Week 9 Resources. Week 8 Class Material. Week 8 Resources. Week 7 Class Material.

hw05 cs61a

Week 7 Resources. Week 6 Class Material. Week 6 Resources. Week 5 Class Material. Week 5 Resources. Week 4 Class Material. Week 4 Resources.GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Skip to content. Permalink Dismiss Join GitHub today GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Sign up. Branch: master. Find file Copy path.

Raw Blame History. Only for testing purposes. Assume that the start pole has at least n disks of increasing size, and the end pole is either empty or has a top disk larger than the top n start disks. Division is implemented as the multiplication of x by the reciprocal of y. Eva is right. Because when an uncertain number is used in computation, the interval span will extend no matter which arithmetic is used sub, add, mul, div.

The less these number is used, the tighter the error bounds would be. The multiple reference problem exists. The true value within a particular interval is fixed though unknown. Nested combinations that refer to the same interval twice may assume two different true values for the same interval, which is an error that results in intervals that are larger than they should be.

No value within this interval, when squared, will give a negative result. Hence, a program like par2 is better than par1 because it never combines the same interval more than once. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Tree definition. There are exactly three poles, and start and end must be different. Move the top disk from rod 1 to rod 3. Move the top disk from rod 1 to rod 2.

Move the top disk from rod 2 to rod 3. Move the top disk from rod 3 to rod 2. Move the top disk from rod 2 to rod 1. Too hard, cannot figure it our on my own. The order is like this:. Official solution. Division is implemented as the multiplication of x by the.

hw05 cs61a

Because when an uncertain number is used in computation, the interval span will extend no matter which. The true value. No value.

Hence, a program like par2 is better than par1 because it never combines. Newton's Method from lecture. Define the polynomial and its first and second derivatives. Actually it's a recursive call. It's a little bit different cause it's from bottom to top.Download hw Inside the archive, you will find a file called hw Submission: When you are done, submit with python3 ok --submit.

You may submit more than once before the deadline; only the final submission will be scored. See Lab 1 for instructions on submitting assignments. Readings: You might find the following references useful:. The following problems use the same tree data abstraction as lecture, but with a different implementation. This mobile example is based on a classic problem from Structure and Interpretation of Computer Programs, Section 2.

A mobile is a type of hanging sculpture. A binary mobile consists of two sides. Each side is a rod of a certain length, from which hangs either a weight or another mobile. We will represent a binary mobile using the data abstractions below, which use the tree data abstraction for their representation. Hint : You should not need to violate the tree abstraction, but this function does need to assume that a mobile is a tree.

Implement the balanced function, which returns whether m is a balanced mobile. A mobile is said to be balanced if the torque applied by its left side is equal to that applied by its right side that is, if the length of the left rod multiplied by the total weight hanging from that rod is equal to the corresponding product for the right side and if each of the submobiles hanging off its sides is balanced.

In lecture, we saw how to use functions to create mutable objects. The returned function should take two arguments: an amount to withdraw and a password.

CS61A Spring 2019 Final Q1

A password-protected withdraw function should only process withdrawals that include a password that matches the original. Upon receiving an incorrect password, the function should:. If a withdraw function has been called three times with incorrect passwords p1p2and p3then it is locked. All subsequent calls to the function should return:.

Suppose that our banking system requires the ability to make joint accounts.

CS 61A: Structure and Interpretation of Computer Programs

Both functions draw down the same balance. Incorrect passwords provided to either function will be stored and cause the functions to be locked after three wrong attempts. Hint : The solution is short less than 10 lines and contains no string literals! The key is to call withdraw with the right password and amount, then interpret the result. You may assume that all failed attempts to withdraw will return some string for incorrect passwords, locked accounts, or insufficient fundswhile successful withdrawals will return a number.

Create a class called VendingMachine that represents a vending machine for some product.This mobile example is based on a classic problem from Structure and Interpretation of Computer Programs, Section 2. A mobile is a type of hanging sculpture. A binary mobile consists of two sides.

Each side is a rod of a certain length, from which hangs either a weight or another mobile. Implement the balanced function, which returns whether m is a balanced mobile. A mobile is balanced if two conditions are met:. The balanced weights assumption is important, since we will be solving this recursively like many other tree problems even though this is not explicitly a tree. Base case : if we are checking a weight, then we know that this is balanced. Why is this an appropriate base case?

There are two possible approaches to this:. Because we know that our data structures so far are trees, weights are the simplest possible tree since we have chosen to implement them as leaves. We also know that from an ADT standpoint, weights are the terminal item in a mobile.

There can be no further mobile structures under this weight, so it makes sense to stop check here. Otherwise : note that it is important to do a recursive call to check if both sides are balanced. However, we also need to do the basic comparison of looking at the total weight of both sides as well as their length. For example if both sides are a weight, trivially, they will both be balanced.

However, the torque must be equal in order for the entire mobile to balanced i. The PDF solution, which I think is so intellectual!! The Fibonacci sequence begins with 0 and then 1, after which each element is the sum of the preceding two.

Use a nonlocal statement! In lecture, we saw how to use functions to create mutable objects. The returned function should take two arguments: an amount to withdraw and a password. A password-protected withdraw function should only process withdrawals that include a password that matches the original. Upon receiving an incorrect password, the function should:.

The PDF solution, which have not a num variable. Suppose that our banking system requires the ability to make joint accounts. Hint: The solution is short less than 10 lines and contains no string literals!

The key is to call withdraw with the right password and amount, then interpret the result. You may assume that all failed attempts to withdraw will return some string for incorrect passwords, locked accounts, or insufficient fundswhile successful withdrawals will return a number.

Each path should be represented as a list of the labels along that path in the tree. You may yield the paths in any order. Then, since a generator is also an iterable, we can iterate over the paths in this generator and yield the result of concatenating it with our current label. This interval arithmetic example is based on a classic problem from Structure and Interpretation of Computer Programs, Section 2.

Alyssa P. Hacker is designing a system to help people solve engineering problems. One feature she wants to provide in her system is the ability to manipulate inexact quantities such as measured parameters of physical devices with known precision, so that when computations are done with such approximate quantities the results will be numbers of known precision.

The result of adding, subracting, multiplying, or dividing two intervals is itself an interval, representing the range of the result.

She also presumes that, given the endpoints of an interval, she can construct the interval using the data constructor interval. She has implemented the constructor for you; fill in the implementation of the selectors.

Louis Reasoner has also provided an implementation of interval multiplication.Submission: When you are done, submit with python3 ok --submit. You may submit more than once before the deadline; only the final submission will be scored. Check that you have successfully submitted your code on okpy.

See Lab 0 for more instructions on submitting assignments. Using Ok: If you have any questions about using Ok, please refer to this guide. Readings: You might find the following references useful:.

Grading: Homework is graded based on effort, not correctness. However, there is no partial credit; you must show substantial effort on every problem to receive any points.

cs61a-hw05

The Fibonacci sequence begins with 0 and then 1, after which each element is the sum of the preceding two. Use a nonlocal statement! In lecture, we saw how to use functions to create mutable objects.

The returned function should take two arguments: an amount to withdraw and a password. A password-protected withdraw function should only process withdrawals that include a password that matches the original. Upon receiving an incorrect password, the function should:. If a withdraw function has been called three times with incorrect passwords p1p2and p3then it is locked.

All subsequent calls to the function should return:. Suppose that our banking system requires the ability to make joint accounts.

Both functions draw from the same balance. Incorrect passwords provided to either function will be stored and cause the functions to be locked after three wrong attempts.

Hint : The solution is short less than 10 lines and contains no string literals! The key is to call withdraw with the right password and amount, then interpret the result. You may assume that all failed attempts to withdraw will return some string for incorrect passwords, locked accounts, or insufficient fundswhile successful withdrawals will return a number.

The following diagram shows the order that the nodes would get printed, with the arrows representing function calls. Complete the Mint and Coin classes so that the coins created by a mint have the correct year and worth.

All questions are required. Readings: You might find the following references useful: Section 2. Upon receiving an incorrect password, the function should: Store that incorrect password in a list, and Return the string 'Incorrect password'. All subsequent calls to the function should return: "Your account is locked.

hw05 cs61a

A password-protected withdraw function, The password with which that withdraw function was defined, and A new password that can also access the original account. Note : This ordering of the nodes in a tree is called a preorder traversal. Each Mint instance has a year stamp. The create method takes a subclass of Coin and returns an instance of that class stamped with the mint 's year which may be different from Mint. A Coin 's worth method returns the cents value of the coin plus one extra cent for each year of age beyond The update method sets the mint's stamp to Mint.GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

Skip to content. Permalink Dismiss Join GitHub today GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Sign up. Branch: master. Find file Copy path.

Cannot retrieve contributors at this time. Raw Blame History. Only for testing purposes. Assume that the start pole has at least n disks of increasing size, and the end pole is either empty or has a top disk larger than the top n start disks.

Division is implemented as the multiplication of x by the reciprocal of y. If the extremum is located inside the interval then Are there more direct pathes?

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. There are exactly three poles, and start and end must be different.

Move the top disk from rod 1 to rod 3. Move the top disk from rod 1 to rod 2. Move the top disk from rod 2 to rod 3. Move the top disk from rod 3 to rod 2. Move the top disk from rod 2 to rod 1. Attempts: ['hwat', 'a', 'n00b']".

Mutable functions

Attempts: ['my', 'secret', 'password']". Extra Questions. Division is implemented as the multiplication of x by the.


comments

Leave a Reply

Your email address will not be published. Required fields are marked *