From 7cad780d820fdf0c810da50a19a0e834091b14bc Mon Sep 17 00:00:00 2001 From: Per <Per Lindgren> Date: Wed, 1 Nov 2017 12:57:33 +0100 Subject: [PATCH] assignment 2 --- README.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3ac26e8..55bcf95 100644 --- a/README.md +++ b/README.md @@ -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.)* -- GitLab