COS 109: Problem Set 6

Due 5:00 PM, Tuesday, Nov 28 by submission to drop box at https://dropbox.cs.princeton.edu/COS109_F2017/Problem_Set_6
Answers need not be long, merely clear so we can understand what you have done. Keep a copy for yourself just in case something goes astray. Thanks.

Collaboration policy for COS 109: Working together to really understand the material in problem sets and labs is encouraged, but once you have things figured out, you must part company and compose your written answers independently. That helps you to be sure that you understand the material, and it obviates questions of whether the collaboration was too close.

You must list any other class members with whom you collaborated.

 

1. Some midterm topics revisited

(a) I recently saw an ad for a robo-investing company that said the following: Investing $25,000 today could result in returns of $200,000 over 30 years . Using the rule of 72, determine the projected annual interest rate for such an investment.

(b) For each of the following strings of hexadecimal digits, tell what colors will be displayed on the monitor

    (i) FEDCBA

    (ii) A9B4C2

    (iii) 9A1B0F

(c) Explain what is output by the Toy program if the inputs are 7 3 2 -4 1 3 0

Foo   GET          get a number from keyboard into accumulator
      IFZERO Bar   if accumulator is zero, go to Bar
      ADD    1     add 1 to accumulator
      ADD    Sum   add the value of Sum to the accumulator
      STORE  Sum   store accumulator in location Sum
      GOTO   Foo   go to instruction labeled Foo
Bar   LOAD   Sum
      PRINT        print contents of accumulator
      STOP
Sum   0   reserve a memory location called Sum, set its initial value to 0

2. A Small Matter of Programming

(a) This Javascript program is supposed to print a table of Celsius temperatures from 0 to 100 inclusive in steps of 10, and their corresponding Fahrenheit temperatures. It is also supposed to print a line above the table that labels the two columns. Not surprisingly, the program contains errors, although the first document.write statement and the formula it contains are correct. Find and fix the errors. (This is a question about logic, not about syntax, but if you put the code into a file and run it, you can be sure that you have identified the errors.)

        var cels = 0;
        while (cels < 100) {
            cels = cels + 1;
            document.write("<br> " + cels + "  " + (9 / 5 * cels + 32));
        }
        document.write("<br> Fahrenheit  Celsius");
 

(b) The following Javascript-like code is supposed to simulate flipping a fair coin exactly 1000 times. At the end, it should print the number of heads and tails. Sadly, it doesn't quite work. Fix the errors. Find and fix the errors. (This is a question about correct logic; don't worry about syntax, but make it very clear what code you're writing.) The Math.random expression is correct: each call of Math.random() produces a new random floating-point value between 0 and 1.

i = 1
heads = 0
print "heads = ", heads, " tails = ", tails 
while (i < 1000) {
     r = Math.random() // random number r >= 0, < 1.0 
     if (r < 0.5) {
          tails = tails + 1
     } else {
          heads = 1
     }
}

(c) The following Javascript function is supposed to count down from the initial value of n to 1, printing the values, then print "Done!" at the end. That is, countdown(3) should print "3, 2, 1, Done!". Unfortunately, it doesn't work. Find and fix the errors. (This is a question about logic, not about syntax, but if you put the code into a file and run it, you can be sure that it works.)

        function countdown(n) {
           i = n
           while (i > n) {
              i = i - 1
              print n
              print "Done!"
           }
        }

 

3. Yet More Numbers

(a) Mac OS X 10.0 (Cheetah) which was released in 2001 required a machine with 128MB of RAM to operate and that OS X 10.12 (Sierra) which was released in 2016 required a machine with 2GB of RAM to operate. How does this compare to what you would expect from Moore's Law?

(b) The first Macintosh operating system (System 1) was released in 1984 and required a machine with 128KB of RAM to operate. How does the change from this operating system to those mentioned in part (a) compare to what you would expect from Moore's Law?

(c) This problem is taken from a sample GRE quantitative reasoning exam. The graph below shows the Corporate Support for the Arts at 2 points in time.

(b)(i) The two corporate sectors that increased their support for the arts from 1988 to 1991 made a total contribution in 1991 of approximately how many million dollars? Give your answer to the nearest 10 million dollars.
    (ii) How many of the six corporate sectors listed each contributed more than $60 million to the arts in both 1988 and 1991?
    (iii) From 1988 to 1991, which corporate sector decreased its support for the arts by the greatest dollar amount?
    (iv) Of the retail sector's 1991 contribution to the arts, one fourth went to symphony orchestras and one half of the remainder went to public television. Approximately how many million dollars more did the retail sector contribute to public television that year than to symphony orchestras?

(d) An article in the Guardian (12/1/13) says that GCHQ (the British equivalent of the NSA) had tapped 200 fiber optic cables, each running at 10 gigabits per second.
    (i) Approximately how many petabytes per day would this amount to?
    (ii) The article says that this would be "equivalent to sending all the information in all the books in the British Library 192 times every 24 hours." From this odd factoid, estimate approximately how many books there are in the British Library. State your assumptions clearly.