|
| 1 | +# Instructions |
| 2 | + |
| 3 | +Mary is a big fan of the TV series _Star Trek: The Next Generation_. She often plays pen-and-paper role playing games, where she and her friends pretend to be the crew of the _Starship Enterprise_. Mary's character is Captain Picard, which means she has to keep the captain's log. She loves the creative part of the game, but doesn't like to generate random data on the spot. |
| 4 | + |
| 5 | +Help Mary by creating random generators for data commonly appearing in the captain's log. |
| 6 | + |
| 7 | +## 1. Generate a random planet |
| 8 | + |
| 9 | +The _Starship Enterprise_ encounters many planets in its travels. Planets in the Star Trek universe are split into categories based on their properties. For example, Earth is a class M planet. All possible planetary classes are: D, H, J, K, L, M, N, R, T, and Y. |
| 10 | + |
| 11 | +Implement the `random_planet` function. It should return one of the planetary classes at random. |
| 12 | + |
| 13 | +```julia-repl |
| 14 | +julia> random_planet_class() |
| 15 | +'K' |
| 16 | +``` |
| 17 | + |
| 18 | +## 2. Generate a random starship registry number |
| 19 | + |
| 20 | +Enterprise (registry number NCC-1701) is not the only starship flying around! When it rendezvous with another starship, Mary needs to log the registry number of that starship. |
| 21 | + |
| 22 | +Registry numbers start with the prefix "NCC-" and then use a number from 1000 to 9999 (inclusive). |
| 23 | + |
| 24 | +Implement the `random_ship_registry_number` function that returns a random starship registry number. |
| 25 | + |
| 26 | +```julia-repl |
| 27 | +julia> random_ship_registry_number() |
| 28 | +"NCC-1947" |
| 29 | +``` |
| 30 | + |
| 31 | +## 3. Generate a random stardate |
| 32 | + |
| 33 | +What's the use of a log if it doesn't include dates? |
| 34 | + |
| 35 | +A stardate is a floating point number. The adventures of the _Starship Enterprise_ from the first season of _The Next Generation_ take place between the stardates 41000.0 and 42000.0. The "4" stands for the 24th century, the "1" for the first season. |
| 36 | + |
| 37 | +Implement the function `random_stardate` that returns a floating point number between 41000.0 and 42000.0 (inclusive). |
| 38 | + |
| 39 | +```julia-repl |
| 40 | +julia> random_stardate() |
| 41 | +41458.15721310934 |
| 42 | +``` |
| 43 | + |
| 44 | +## 4. Generate a rounded stardate |
| 45 | + |
| 46 | +There have been complaints about having too many decimal points in stardates, so Mary decides to round logs to one decimal place. |
| 47 | + |
| 48 | +Though this could be done by rounding values from `random_stardate()`, you realize that there is a much simpler approach. |
| 49 | + |
| 50 | +Implement the function `random_stardate_v2` that returns a floating point number between 41000.0 and 42000.0 (inclusive), with a single decimal place. |
| 51 | + |
| 52 | +```julia-repl |
| 53 | +julia> random_stardate_v2() |
| 54 | +41732.6 |
| 55 | +``` |
| 56 | + |
| 57 | +## 5. Pick some random starships from a list. |
| 58 | + |
| 59 | +One version of the game involves interacting with other starships, and Mary needs a selection. |
| 60 | + |
| 61 | +There is a full list of possible starships, but only a few of these is needed in each game, and they should be chosen at random. |
| 62 | + |
| 63 | +Implement the `pick_starships(starships, number_needed)` function, which takes a vector of unique starship registry numbers, and returns a vector of length `number_needed`. |
| 64 | +Result values should be taken from `starships`, with no duplicates. |
| 65 | + |
| 66 | +```julia-repl |
| 67 | +julia> pick_starships(["NCC-5011", "NCC-1228", "NCC-7039", "NCC-3978", "NCC-1476"], 2) |
| 68 | +2-element Vector{String}: |
| 69 | + "NCC-1228" |
| 70 | + "NCC-5011" |
| 71 | +``` |
| 72 | + |
| 73 | +## _5a. Optionally, think about other argument types._ |
| 74 | + |
| 75 | +We constrained the `starships` argument to be a vector. |
| 76 | +How would you implement `pick_starships()` to work with other iterables, such as tuples or sets? |
| 77 | + |
| 78 | +There are no tests for this part. |
0 commit comments