DOC PREVIEW
Berkeley CS 61A - 2009Fa UC Berkeley CS39n Midterm Answers

This preview shows page 1-2 out of 6 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS39n - M idte rm ± SO L U T I O N 2009/10/26 1. a) The gray arrow represents the FINAL location of the arrow. b) c) d) e) f)2. Solution: The value of result is: 6420 This was pretty tricky because the starting value of result (the zero) matters! Another tricky part was that the last line sets the result to be the join of index and result. As a result the next value of index is added to the FRONT of the existing numbers. CS39n - M idte rm - PA R T 2 Programming: 3. Solution: we could have either the cat or the bananas detect when they touch and broadcast a message to the monkey. It is important that the cat knows to stop walking when it touches the bananas so we might as well KDYH LW EURDGFDVW WKH PHVVDJH WR WKH PRQNH\ :KHQ WKH PRQNH\ UHFHLYHV WKH PHVVDJH LW VKRXOG VD\ ³*HW DZD\ IURP P\ EDQDQDV´4. Solution: We can use lists to keep track of the mapping between the numbers 1-3 and WKH ZRUGV ³URFN´ ³SDSHU´ DQG ³VFLVVRUV´ ,QVWHDG RI KDYLQJ  LI¶V IRU HDFK FKDUDFWHU ZH FDQ KDYH WKHP XVH WKHLU UDQGRP QXPEHU WR LQGH[ LQWR D OLVW WKDW FRQWDLQV ³URFN´ ³SDSHU´ DQG ³VFLVVRUV´ 5. Solution:Short Answe r: 6. Aside from the reasons we discussed in class (simulations for training and Luis von Ahn's games with a purpose), what is a great use of games, in terms of a benefit to society / individuals? Possible Answers: (1) Wii fit (keeps people in shape), (2) Games more and more have a social component, which can contribute to the feeling of being part of a community (for isolated individuals), (3) Games provide livelihoods to developers, retailers, artists, etc. (4) Designing games is a tremendous creative outlet (5) Games allow escapism (6) They can serve to define a generation (7) They can teach logical, computational thinking (8) Games can be a great way (read: Siren Song) for people to get interested in computing 7. What is a disadvantage of duplicating a sprite many times? If you could redesign Scratch, how would you eliminate this problem? Possible Disadvantages x It becomes difficult to change the costumes because you have to change each one individually x It becomes difficult to keep all of the code the same for each sprite because if you need to make one change you must remember to change each one individually. Possible Solutions x +DYH RQH ³PDVWHU´ VSULWH ZKHUH DOO RI WKH RWKHU VSULWHV FDQ VKDUH RQH FRS\ RI FRVWXPHV DQG VFULSWV x Have a hierarchy of sprites so that individual sprites can automatically have the functionality of things higher in the hierarchy and can make modifications as they wish. x Have Scratch keep track of which sprites have been copied so that you can easily monitor and change the differences between the scripts/costumes for each script. 8. We want a character to say the first word in the sentence ("Go" in the examples below). Other characters may also be using first. a) 6ROXWLRQ :H ZLOO DFFHSW WKH DQVZHUV RI ERWK ³VRPHWLPHV´ DQG ³QHYHU´ :KHQ ZH EURDGFDVW ³ILUVW´ WKH ILUVW script starts to compute the value of result. There is no guarantee that this script has finished computing the value of result before we try to say the value in the result variable. b) 6ROXWLRQ ³VRPHWLPHV´ :KHQ ZH EURDGFDVW ³ILUVW´ WKH ILUVW VFULSW VWDrts to compute the value of result and luckily this time we wait for it to finish before trying to say the value in the result variable. Unfortunately there may be many other sprites/scripts trying to use the same variables of sentence and result. Consider the scenario ZKHUH RQH VSULWH EURDGFDVWV WKH PHVVDJH ³ILUVW´ DQG WKHQ EHIRUH WKH VFULSW WKDW UHFHLYHV ³ILUVW´ ILQLVKHV H[HFXWLQJ another sprite broadcasts first. Scratch really should handle this better, but what currently happens is that one of WKH VFULSWV WKDW EURDGFDVWHG ³ILUVW´ ZLOO QHYHU ILQLVK DQG ZLOO WKHUHIRUH QHYHU VD\ ³UHVXOW´ 7KH PRUH JHQHULF answer is that the result of first might be from your call to ILUVW DQG LW PLJKW EH IURP DQRWKHU VSULWH¶V FDOO WR ILUVW c)Solution: This always works. The reason is that by using the block first, even if someone else changes the value RI ³VHQWHQFH´ WKH EORFN FDQ VWLOO H[HFXWH ZLWKRXW EHLQJ LQWHUUXSWHG RU PHVVHd up. 9. In a hybrid car, the electric motor can also serve as a generator to recharge the battery, by letting the wheels turn the motor instead of the other way around. This takes energy away from the wheels, slowing the car. To make this happen, you push the brake pedal. But you're not really applying the brakes -- you're charging the battery from the car's energy of motion. So why didn't they make a separate control for this, instead of giving an extra meaning to the brake pedal? Solution: As we GLVFXVVHG LQ FODVV SDUW RI KRZ FDUV DUH GHVLJQHG LV WKDW WKHUH LV DQ DEVWUDFWLRQ VR WKDW FDUV GRQ¶W QHHG WR NQRZ KRZ SHRSOH ZRUN DQG WKDW SHRSOH GRQ¶W QHHG WR NQRZ KRZ FDUV ZRUN %\ SURYLGLQJ D GLIIHUHQW pedal would increase the amount that people needed to know about a car in order to be able to drive it. So the extra pedal breaks the abstraction between humans and cars. Presumably the car can figure out when you should press the brake and when you should just convert the energy to charge the battery and can probably do so better than a human driver would be able to do. 10. "I don't do anything I'm ashamed of; why should I worry about privacy?" Give at least two answers to that question. Possible Answers: x With less privacy comes the increased opportunity for others to steal your identity. x We behave differently in different contexts. What is appropriate in one context may be inappropriate in another. In the future you will be in different situations, one of which may make some of your behavior that is captured online inappropriate. x With less privacy it is easier for others to inappropriately/illegally discriminate against you based upon non-shameful aspects of your identity. 11. What's the difference between strongly and weakly solving a game? Solution: Strongly solving involves visiting EVERY position, and knowing what to do in every situation. Weakly solving means you can prove things about the game (e.g., Checkers is a tie game) but may not know how to play every possible game perfectly. 12. In the future, when computers have thousands of cores (simultaneous processing modules), which of the programming paradigms will be easiest to automatically parallelize and why? Solution:


View Full Document

Berkeley CS 61A - 2009Fa UC Berkeley CS39n Midterm Answers

Download 2009Fa UC Berkeley CS39n Midterm Answers
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view 2009Fa UC Berkeley CS39n Midterm Answers and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view 2009Fa UC Berkeley CS39n Midterm Answers 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?