CSC 550: Introduction to Artificial Intelligence
Fall 2004

HW2: Scheme and AI programming


  1. Define functions named inches->meters and pounds->kilograms, each of which takes a number as input and performs the specified conversion on that number. Note that 1 meter is 39.37 inches and 1 kilogram is 2.2 pounds.

  2. Define a function named body-mass-index that takes two inputs, a person's height (in inches) and weight (in pounds), and returns their "body mass index." Body mass index is computed by the following formula:

        body mass index = (weight in kilograms) / (height in meters)2
    
  3. According to the U.S. Centers for Disease Control (CDC), a man is considered to be obese if his body mass index is 27.8 or greater, while a woman is considered obese if her index is 27.3 or greater. Define a predicate function named obese? that takes three inputs, a symbol specifying gender (either 'M or 'F) and that person's height (in inches) and weight (in pounds), and returns either #t or #f to classify the person as obese or not.

  4. Define a function named remove that takes two inputs, an atom and a list, and returns the list with each occurrence of the atom removed. For example, (remove 'x '(z x e x)) should evaluate to (z e).

  5. Similarly, define a function named remove-below that takes two inputs, a number and a list of numbers, and returns the list but with every number less than the first input removed. For example, (remove-below '90 '(95 80 90 17)) should evaluate to (95 90).

  6. Similarly, define a function named filter that takes two inputs, a predicate function and a list. Your function should apply the provided predicate function to each element of the list, and filter out those elements for which the function returns #f. For example, (filter even? '(95 80 90 17)) should evaluate to (80 90).

  7. Define a function named prime? that takes one input, a positive integer, and returns #t if that number is prime, else #f. For example, (prime? 6) should evaluate to #f, while (prime? 7) should evaluate to #t. Your function should only utilize tail-recursion (perhaps a help function will be required).

  8. Define a function named range that takes two inputs, the low and high integers in a range, and returns a list containing all integers in that range. For example, (range 1 5) should evaluate to (1 2 3 4 5).

  9. Utilizing the functions you have just written, define a function named primes-in-range that takes two inputs, the low and high integers in a range, and returns a list of all of the prime numbers in that range. For example, (primes-in-range 10 20) should evaluate to (11 13 17 19).

  10. In class, we discussed a format for representing binary trees as Scheme lists, and even defined function for accessing the root and subtrees of a tree structure. Using these functions, define a new function named num-nodes which takes one input, a tree structure, and returns the number of nodes (values) stored in that tree. Hint: think recursively. If you knew the number of nodes in the left and right subtrees, how would you then compute the total number of nodes?

  11. Copy the Eliza program from www.creighton.edu/~davereed/csc550/Code/eliza.scm and make the following modifications: