## HtDP Problem Set | ## Section 5 |

Problem 1:

Develop the functiondescribe-temp, which consumes a Celsius temperature and returns 'Warm if the temperature is 25 or greater, 'Mild if the temperature is between 10 and 25, and 'Cold if the temperature is below 10.

Problem 2:

Develop a function that when given a symbol and number returns the square root of the number if the symbol is 'squareroot or the tangent of the number if the symbol is 'tangent. For all other symbols, it returns the original number.

Problem 3:

Modifycheck-guessfrom Exercise 5.1.2 (duplicated below) to add a fourth response, 'WithinTen, which is returned when the player's guess is in the range of ten above or below the target.

Exercise 5.1.2Develop the function

check-guess. It consumes two numbers,guessandtarget. Depending on howguessrelates totarget, 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 thatcheck-guessimplements.The function

check-guessand the teachpackimplement the first player. The teachpack picks the random number, pops up a window in which the second player can choose digits, and hands over theguess.ssguessand thetargettocheck-guess. To play the game, set the teachpack tousing theguess.ss`Language|Set teachpack`

option. Then evaluate the expressionafter(guess-with-gui check-guess)check-guesshas been thoroughly tested.

Problem 4:

Inhabitants of the island of knaves always walk around in pairs. Each will respond with 'Yes or 'No individually when asked an appropriate question. You can only be certain of having received an affirmative answer if both reply 'Yes. All other combinations imply 'No.

Develop the function

discern, which will accept all pairwise combinations of knaves' answers and produce 'Yes or 'No accordingly.

Problem 5:

A robot car is confined to a narrow straight track that is marked with positions 0 through 99.

Develop the function

move. It consumes a command (either 'Forward or 'Backward), the number of units to move, and the current position of the robot, then returns the new position of the robot. The robot cannot go off the end of the track, so once it has reached either end it will remain there.

Jamie Raymond | Matthias Felleisen |

01 december 2003 |