![]() |
![]() |
|
Due:
Your submitted file should be named “hw03.rkt”.
We wish to write code about whether or not the Radford Highlanders won their basketball game, this last weekend. We want to capture: whether they won/lost, or tied, or there wasn't any game this weekend, or (if the game is still in-progress) what the name of the team currently being played is. (Oddly, we will not track the opposing team's name when the game isn't in progress1. Perhaps we don't care about such details once a game is over?)
Hint: To represent whether they won or lost, a boolean would be appropriate. What types seem appropriate for each of the other variants?
hint: This function's signature is (-> game-result? .
Hint: Of course, it is not “as appropriate” to return a string mentioning The Wytheville Wallabies when we're actually playing The Dublin Dingoes, or The Pulaski Pangolins! Recall from our data-definition in #1, a game-result should capable of representing, among other things, the name of a team (which therefore means that the game must be in-progress). (Moreover, this means your function does not need to be given any additional information, since the game-result already represents the info you need.)
Team names: We'll consider the word “The” to be part of the team-name. This covers the situation where RU's soccer team might play, say, Manchester United.
(40pts) Various rovers on Mars (Curiosity) and the moon (Yutu 2) take scientific measurements, including oxygen-levels in the atmosphere (indicating the capability to support life), and actual signs of life (by-products like methane, or perhaps finding actual bacteria or other life!) Occasionally, the equipment might malfunction and give no result.
A rover-measurement is one of:
In turn, a lifesign is one of:
Some lifesigns are stronger indicators than others; we'll say the "strength" of a lifesign (on a scale of 0 to 1) is: 1.0 for a species, and for by-products it's 0.1 per character in the chemical-name (with a maximum possible value of 1, of course). (Longer, fancier chemical-names are more likely the result of an organic process?) E.g. 'urea has a strength of 0.4; 'ammonia a strength of 0.7; 'monosodium-glutamate (20 characters) would max out at 1.0.
hint: In addition to string-length and max, symbol->string will be helpful.
Write the function newsworthy, which takes a rover-measurement, and returns how newsworthy it is (on a scale of 0 to 1): A sensor-failure rates 0.10. For a life-sign, the newsworthiness is twice its strength (maxing out at 1, of course). Oxygen levels only start to become newsworthy after 5% of earth's level, increasing linearly5 until they are totally newsworthy at 25% (or more) of earth's level.
hint: Figuring out exactly what your code needs to do becomes easier after writing your unit-tests.
remember: Follow all steps of the design recipe as appropriate, of course. If handling a union-type, and one variant happens to itself be another union-type, a helper-function is more appropriate than having one function which does all the details of two different union types.
“One function, one task”: If a concept like "lifesign strength" is its own definition (described in its own paragraph above), then good design suggests it’s probably worth its own function, rather than being anonymously folded into a larger function that does even more.
Standard instructions for all homeworks (unless instructed otherwise):
(And on further thought, we'll also note that while opposing-team-name could conceivably be information worth tracking for several cases, it wouldn't make sense for no-game-this-week. This complicates a correct data-representation; more on that in class.)
↩This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |