EXERCISE SET #7

1. The version of the map procedure presented as program 7.1 in the textbook (page 196) does not use an iterative process. Write one that does.

2. Define a ``curried'' version of the filter procedure from exercise 9 of set #4 -- a procedure that takes a predicate as argument and returns a procedure that filters non-conforming elements out of lists.

3. Define a Scheme procedure that takes a list of strings as arguments and returns a list containing strings that are exactly similar except that each vowel in each string has been replaced by a hyphen.

4. Define a Scheme procedure that returns a list of thirty three-letter strings in which the first letter is chosen randomly from the set bdfghjklmnprstvz, the second from the set aeiou, and the third from the set bdfgklmnprstvxz.

5. Define a Scheme procedure lookup that takes a value and a list of pairs and returns the cdr of the first pair on the list that has the given value as its car. For example, (lookup 'a '((b . 2) (c . 3) (a . 1))) should return 1.

6. Define a Scheme procedure consume-line, of arity 0, that reads in and discards characters from the keyboard up to and including the next newline character.

7. The file /u2/stone/events/scheme-workshop/examples/penny-matcher.scm contains an interactive program that will match pennies with the user for one hundred rounds, winning whenever it succeeds in matching the user's choice of heads or tails on a given round, losing when its own choice doesn't match the user's. The program works by building a very simple model of the user's behavior.

Run this program in batch mode and report the outcome after one hundred rounds. Then study the source code and describe the cognitive model that it relies on.

8. Currently the penny-matching program sometimes chooses its plays randomly. Revise it so that it always plays tails in these cases, trying to induce the player to bias her choices towards heads. Keep track of the number of times the player chooses heads and incorporate that information into the final report of the match.

9. Currently the penny-matching program assumes that whenever its opponent faces a situation that she has been in before, she'll tend to behave the same way. Revise it so that, if the situation has arisen only once before, the program predicts that the opponent will remember what she did before and do the opposite this time. (On subsequent recurrences of the situation, the program should behave as it does now -- that is, whenever the situation has arisen more than once in previous rounds, the program should predict that its opponent will choose the play that she has most frequently chosen in the past in the same situation.) The idea is to model the cognition of a ``tricky'' player who tries to avoid establishing exploitable patterns, but has a shallow memory of her previous plays and their contexts.

10. Design a strategy for the penny-matching game that can regularly defeat the initial version of penny-matcher. Implement it as a Scheme procedure and replace the select-your-move procedure in the penny-matcher program with that procedure to prove that it can win.


created June 17, 1996
last revised June 18, 1996

John David Stone (stone@math.grin.edu)