Finger Exercises with Symbols

<#3557#>Exercise 5.1.1<#3557#> Evaluate <#60889#><#3559#>(reply<#3559#>\ <#3560#>'<#3560#><#3561#>HowAreYou?<#3561#><#3562#>)<#3562#><#60889#> and <#60890#><#3563#>(reply<#3563#><#3564#> <#3564#><#3565#>'<#3565#><#3566#>GoodEvening)<#3566#><#60890#>.~ external Solution<#60891#><#60891#> external ~<#70731#>The next few exercises involve conditional reasoning in addition to symbol-processing. Remind students to identify the possible situations and to design examples/tests and <#60892#><#3573#>cond<#3573#><#60892#>-expressions accordingly. Exercise~#exguess1#3574> is the beginning of a series of exercises: #exguess2#3575>, #exguess3#3576>, #exguessgui#3577>. Each of the exercises gives the students a bit more control over the game until they eventually write the entire function. The next one, exercise~#exguess2#3578>, also reminds students that we need to develop a program per concept if we don't want things to get out of hand.<#70731#> <#3579#>Exercise 5.1.2<#3579#> Develop the function <#60893#><#3582#>check-guess<#3582#><#60893#>. It consumes two numbers, <#60894#><#3583#>guess<#3583#><#60894#> and <#60895#><#3584#>target<#3584#><#60895#>. Depending on how <#60896#><#3585#>guess<#3585#><#60896#> relates to <#60897#><#3586#>target<#3586#><#60897#>, the function produces one of the following three answers: <#60898#><#3587#>'<#3587#><#3588#>TooSmall<#3588#><#60898#>, <#60899#><#3589#>'<#3589#><#3590#>Perfect<#3590#><#60899#>, or <#60900#><#3591#>'<#3591#><#3592#>TooLarge<#3592#><#60900#>. 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 <#60901#><#3593#>target<#3593#><#60901#>, with the least number of guesses. To each guess, the first player responds with one of the three responses that <#60902#><#3594#>check-guess<#3594#><#60902#> implements. The function <#60903#><#3595#>check-guess<#3595#><#60903#> and the teachpack <#3596#>guess.ss<#3596#> 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 <#60904#><#3597#>guess<#3597#><#60904#> and the <#60905#><#3598#>target<#3598#><#60905#> to <#60906#><#3599#>check-guess<#3599#><#60906#>. To play the game, set the teachpack to <#3600#>guess.ss<#3600#> using the 2 option. Then evaluate the expression
<#3605#>(repl<#3605#> <#3606#>check-guess)<#3606#>
after <#60907#><#3610#>check-guess<#3610#><#60907#> has been thoroughly tested.~ external Solution<#60908#><#60908#> <#3616#>Exercise 5.1.3<#3616#> Develop the function <#60909#><#3619#>check-guess3<#3619#><#60909#>. It implements a larger portion of the number guessing game of exercise~#exguess1#3620> than the function <#60910#><#3621#>check-guess<#3621#><#60910#>. Now the teachpack hands over the <#60911#><#3622#>digits<#3622#><#60911#> 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, <#60912#><#3623#>check-guess3<#3623#><#60912#> consumes three digits and a number. The first digit is the least significant, the third one is the most significant. The number is called <#60913#><#3624#>target<#3624#><#60913#> and represents the randomly chosen number. Depending on how <#60914#><#3625#>guess<#3625#><#60914#>, the number determined by the three digits, relates to <#60915#><#3626#>target<#3626#><#60915#>, <#60916#><#3627#>check-guess3<#3627#><#60916#> produces one of the following three answers: <#60917#><#3628#>'<#3628#><#3629#>TooSmall<#3629#><#60917#>, <#60918#><#3630#>'<#3630#><#3631#>Perfect<#3631#><#60918#>, or <#60919#><#3632#>'<#3632#><#3633#>TooLarge<#3633#><#60919#>. The rest of the game is still implemented by <#3634#>guess.ss<#3634#>. To play the game with <#60920#><#3635#>check-guess3<#3635#><#60920#>, evaluate
<#3640#>(repl3<#3640#> <#3641#>check-guess3)<#3641#>
after the function has been thoroughly tested. <#3645#>Hint:<#3645#> Remember to develop an auxiliary function per concept.~ external Solution<#60921#><#60921#> <#3651#>Exercise 5.1.4<#3651#> Develop <#60922#><#3653#>what-kind<#3653#><#60922#>. The function consumes the coefficients <#60923#><#3654#>a<#3654#><#60923#>, <#60924#><#3655#>b<#3655#><#60924#>, and <#60925#><#3656#>c<#3656#><#60925#> 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: <#60926#><#3657#>'<#3657#><#3658#>degenerate<#3658#><#60926#>, <#60927#><#3659#>'<#3659#><#3660#>two<#3660#><#60927#>, <#60928#><#3661#>'<#3661#><#3662#>one<#3662#><#60928#>, or <#60929#><#3663#>'<#3663#><#3664#>none<#3664#><#60929#>. <#3665#>Hint:<#3665#> \ Compare with exercise~#exquad1#3666>.~ external Solution<#60930#><#60930#> <#3672#>Exercise 5.1.5<#3672#> #drnexcheckguess#3675> Develop the function <#60932#><#3676#>check-color<#3676#><#60932#>. 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 check the colors and to produce one of the following answers:
  1. <#60933#><#3678#>'<#3678#><#3679#>Perfect<#3679#><#60933#>, if the first target is equal to the first guess and the second target is equal to the second guess;
  2. <#60934#><#3680#>'<#3680#><#3681#>OneColorAtCorrectPosition<#3681#><#60934#>, if the first guess is equal to the first target or the second guess is equal to the second target;
  3. <#60935#><#3682#>'<#3682#><#3683#>OneColorOccurs<#3683#><#60935#>, if either of the guesses is one of the two targets;
  4. and <#60936#><#3684#>'<#3684#><#3685#>NothingCorrect<#3685#><#60936#>, otherwise.
These four answers are the only answers that the first player gives. The second player is to guess the two chosen target colors with as few guesses as possible. The function <#60937#><#3687#>check-color<#3687#><#60937#> simulates the first player's checking action. It consumes four colors; for simplicity, we assume that a color is a symbol, say, <#60938#><#3688#>'<#3688#><#3689#>red<#3689#><#60938#>. The first two arguments to <#60939#><#3690#>check-color<#3690#><#60939#> are ``targets,'' the latter two are ``guesses.'' The function produces one of the four answers. When the function is tested, use the teachpack to <#3691#>master.ss<#3691#> to play the color-guessing game. The teachpack provides the function <#60940#><#3693#>master<#3693#><#60940#>. Evaluate <#60941#><#3694#>(master<#3694#>\ <#3695#>check-color)<#3695#><#60941#> and choose colors with the mouse.~ external Solution<#60942#><#60942#>