For this assignment, you are to define the following Scheme functions. For simplicity, place all of your function definitions in a single file named YOURNAME-hw5.ss, where YOURNAME is your name. Be careful to name your functions exactly as defined in the exercises, and be sure to comment each function as to its behavior.
dew-point = temp - (100 - humidity)/2.778
cloud-base = 1000 * (temp - dew-point)/4.4
wind-chill = { temperature if windSpeed <= 3 35.74 + 0.6215*temperature + (0.4275*temperature-35.75)*windSpeed0.16 otherwise
dew-point-metric
function that takes its temperature in degrees Celsius and returns the dew-point in degrees Celsius. Likewise, cloud-base-metric
would take its temperature in degrees Celsius and return the cloud-base in meters. Finally, wind-chill-metric
would take its temperature in degrees Celsius and its wind-speed in km/hr and return the wind-chill in degrees Celsius. Define functions for doing the necessary metric conversions (e.g., ft->m
, fahr->celsius
) and use them along with your existing functions to define the new metric-based weather functions.You may assume the ancient roman style of writing letters, where 4 is
represented IIII and 90 is represented LXXXX. A harder problem, which
you may attempt if you like, is to use the modern roman style where
4 is IV and 90 is XC.
dice-roll
that has no inputs and simulates the roll of two six-sided dice. That is, the call (dice-roll)
should return an integer from the range 2 through 12, following the appropriate probability distribution (e.g., 7 is the most likely roll, 2 and 12 are the least likely).
Hint: The built-in random
function generates a pseudo-random integer from 0 up to its input (exclusive). For example, the call (random 4)
would return either 0, 1, 2, or 3.
average-rolls
that takes one input, a positive integer, and simulates that many rolls of the dice, returning the average of all of those rolls. For example, the call (average-rolls 1000)
should simulate 1000 dice rolls and return the average. Since the number of rolls could be large, your function should utilize tail-recursion. count-dice
that takes two inputs, a number of rolls and the desired total. The function should simulate the specified number of rolls and return the number of times the desired total was obtained. For example, the call (count-dice 1000 7)
should simulate 1000 dice rolls and return the number of times 7 was rolled. Since the number of rolls could be large, your function should utilize tail-recursion. random-walk
function below simulates a random 1-dimensional walk. Initially,
the
walker is assumed to be at position 0. Depending on the flip of a coin, the
walker
either moves to the right (in the positive direction) or to the left (in the
negative direction). The simulation ends when the walker reaches the
specified goal
distance, in
either direction.
As is, this function simulates steps in the walk and returns the final position of the walker. Modify the function so that it keeps a list of all the steps in the walk and returns this list instead (with starting position 0 at the front and the final position at the end). Your modification should only utilize tail-recursion.