CS 536 Homework 1: Warming up in Scheme

Due: September 15 in class (hardcopy)


Assignment Goals


Exercises

  1. Define the function suffixes, which consumes a list l, and produces a list of all suffixes of l. For example:

        (suffixes '(a b c d))
        > ((a b c d) (b c d) (c d) (d) ())
    
  2. Develop a program isort to sort a list of numbers into increasing order. You may use any algorithm you wish (efficiency doesn't matter, but cleanliness of your solution does).

  3. Define a datatype for toys. A toy is one of:

  4. Develop the function bear-sale that consumes a list of toys and returns a list of toys. The returned list has the same toys as the input list, but the prices on all bears have been discounted 20%.

  5. Develop the function eliminate-exp to eliminate expensive toys. The function consumes a price (number) and a list of toys and produces a list of all those toys that cost no more than the given price.

  6. Develop the function tall-programmable? that consumes a list of toys and returns a boolean indicating whether the list contains a programmable robot more than 3 feet tall.

  7. Define a datatype for a family tree. A family tree is either:

    For example, a small family tree looks like:

        
        (person "Dave" 1977 'brown
                (person "Ken" 1945 'brown
                        (unknown)
                        (unknown))
                (person "Mary Ellen" 1946 'brown
                        (unknown)
                        (unknown)))
    

  8. Develop count-persons. The function consumes a family tree node and produces the number of people in the corresponding family tree.

  9. Develop the function average-age. It consumes a family tree node and the current year. It produces the average age of all people in the family tree. You may assume that the given tree contains at least one person.

  10. Develop the function eye-colors, which consumes a family tree node and produces a list of all eye colors in the tree. Each eye color should occur at most once in the list.

    Hint: Use the Scheme operation append, which consumes two lists and produces the concatenation of the two lists. For example:

    (append (list 'a 'b 'c) (list 'd 'e)) = (list 'a 'b 'c 'd 'e)


Back to the Assignments page