Skip to content
Snippets Groups Projects
Commit 7cad780d authored by Per's avatar Per
Browse files

assignment 2

parent 43f01578
Branches
No related tags found
No related merge requests found
......@@ -115,16 +115,19 @@ Seminars
* [9 - Error Handling](https://doc.rust-lang.org/book/second-edition/ch09-00-error-handling.html).
* Assignment 2
a. Break out the line input into a function returning a `Result<Ok<u32>>, Err<String>>`. In case of a parsing error prepend the `Err<String>` with the text `"in parsing u32, "`.
a. Extend the guessing game with a tuple holding `(u32, String)`, store each input `(counter, guess)` in a vector. Iterate (`for`) to print the history at exiting.
b. Extend the guessing game with a tuple holding `(u32, String)`, store each input `(counter, guess)` in a vector. Iterate (`for`) to print the history at exiting. You may solve this in many ways (perhaps your first attempt would be a C like approach), however make use of `Iterator`s in Rust (they will do the indexing for you).
b. Instead of vector use a 'HashMap', with a key `u32` and a value `String`. Again iterate (`for`) to print the history at exiting. (Explain the result.)
c. Change the program so that it prints the history twice.
c. Break out the line input into a function returning a `Result<Ok<u32>>, Err<String>>`. In case of a parsing error prepend the `Err<String>` with the text `"in parsing u32, "`.
d. Change the program so that it prints only the last 3 entries in backwards order (the last entry first). If winning with less than 3 entries, print all (still in backwards order). Use iterators (not C-like indexing).
d. Optional, find a way to print the `HashMap` in a sorted way.
e. Instead of vector use a 'HashMap', with a key `u32` and a value `String`. Again iterate (`for`) to print all entries at exiting. (Explain the result.)
Make three new branches (`2a, 2b, 2c`) whith your code, along with a README.md for usage instructions, and expected behavior.
f. Optional, find a way to print the last 3 entries of the `HashMap` (output similar to d).
Make new branches (`2a, 2b, ..., 2f`) with your solutions, along with a README.md for usage instructions, and expected behavior.
*During development you may want to limit the number of tries so you can test without having to bother with answering correctly (the game gets boring after a while.)*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment