Exercise 5.1.1
Evaluate (reply 'HowAreYou?) by hand and with DrScheme's stepper. Formulate a complete set of examples for reply as boolean expressions (using symbol=?). Solution
Exercise 5.1.2
Develop the function check-guess. It consumes two numbers, guess and target. Depending on how guess relates to target, the function produces one of the following three answers: 'TooSmall, 'Perfect, or 'TooLarge.
The function implements one part of a two-player number guessing game. One player picks a random number between 0 and 99999. The other player's goal is to determine this number, called target, with the least number of guesses. To each guess, the first player responds with one of the three responses that check-guess implements.
The function check-guess and the teachpack guess.ss implement the
first player. The teachpack picks the random number, pops up a window in which
the second player can choose digits, and hands over the guess and the
target to check-guess. To play the game, set the
teachpack to guess.ss using the Language|Set teachpack option.
Then evaluate the expression
(guess-with-gui check-guess)after check-guess has been thoroughly tested. Solution
Exercise 5.1.3
Develop the function check-guess3. It implements a larger portion of
the number guessing game of exercise
than the function
check-guess. Now the teachpack hands over the digits that
the user guesses, not the number that they form.
To simplify the problem a little bit, the game works with only three numbers. Thus, check-guess3 consumes three digits and a number. The first digit is the least significant, the third one is the most significant. The number is called target and represents the randomly chosen number. Depending on how guess, the number determined by the three digits, relates to target, check-guess3 produces one of the following three answers: 'TooSmall, 'Perfect, or 'TooLarge.
The rest of the game is still implemented by guess.ss. To play the game with check-guess3, evaluate
(guess-with-gui-3 check-guess3)after the function has been thoroughly tested.
Hint: Remember to develop an auxiliary function per concept. Solution
Exercise 5.1.4
Develop what-kind. The function consumes the coefficients a, b, and c of a quadratic equation. It then determines whether the equation is degenerate and, if not, how many solutions the equation has. The function produces one of four symbols: 'degenerate, 'two, 'one, or 'none.
Hint: Compare with exercise
. Solution
Exercise 5.1.5
Develop the function check-color. It implements a key portion of a color guessing game. One player picks two colors for two squares; we call those targets. The other one tries to guess which color is assigned to which square; they are guesses. The first player's response to a guess is to check the colors and to produce one of the following answers:
The function check-color simulates the first player's checking action. It consumes four colors; for simplicity, we assume that a color is a symbol, say, 'red. The first two arguments to check-color are ``targets,'' the latter two are ``guesses.'' The function produces one of the four answers.
When the function is tested, use the teachpack to master.ss to play
the color-guessing game.
The teachpack
provides the function master. Evaluate (master check-color)
and choose colors with the mouse. Solution