ICS 1F, Homework 1

Due Friday, January 16th, at the end of class

  1. List three things you think computers can now do better than you, and three things you think you can do better than computers.

  2. Is there a (whole number) value of x that would cause an infinite loop in the procedure described below? Explain why or why not. (Hint: Try it with a few small numbers to see what happens.)

        Read a number x.
        Initialize a counter to zero.
    
        While x is greater than zero, perform the following steps:
    
            Increase the counter by one.
            If x is odd, replace x by (x+1)/2;
            otherwise (if x is even) replace x by x-2.
    
        Once the loop terminates (if it does),
        output the value of the counter and halt.
    

  3. In the imaginary country of Binaria, the currency is based on the centina, which is worth approximately the same as a penny. The coins of Binaria have values that are powers of two: 1, 2, 4, 8, 16, 32, and 64 centinas.

    (a) What coins should you use to make change for the following amounts of money? (In each case answer with the smallest possible set of coins that adds up to the correct value.)

    1. 15 centinas
    2. 29 centinas
    3. 39 centinas
    4. 108 centinas

    (b) Why might it be useful for Binarian cash registers to display amounts of money using binary notation?