From 639680a498225b044c99e99dc77a281aec9f705d Mon Sep 17 00:00:00 2001 From: davidrobert99 Date: Wed, 23 Mar 2022 18:33:24 +0000 Subject: [PATCH] correction of typos, some small corrections --- subjects/generics/README.md | 6 ++++++ subjects/highest/README.md | 16 +++++++-------- subjects/matrix/README.md | 8 +++++--- subjects/matrix_mult/README.md | 6 +++--- subjects/sales/README.md | 30 ++++++++++++++--------------- subjects/slices_to_map/README.md | 2 ++ subjects/spelling/README.md | 3 --- subjects/talking/README.md | 2 +- subjects/traits/README.md | 14 ++++++++++---- subjects/unwrap_or_expect/README.md | 6 +++--- 10 files changed, 52 insertions(+), 41 deletions(-) diff --git a/subjects/generics/README.md b/subjects/generics/README.md index f53e8b65..571cfaf6 100644 --- a/subjects/generics/README.md +++ b/subjects/generics/README.md @@ -4,6 +4,12 @@ Write a **function** called `identity` which calculates the identity of a value (receives any data type and returns the same value). + +### Notions + +- [Generics](https://doc.rust-lang.org/book/ch10-01-syntax.html) + + ### Expected Function (signature to be completed) ```rust diff --git a/subjects/highest/README.md b/subjects/highest/README.md index dcd7ea32..b4b71ba4 100644 --- a/subjects/highest/README.md +++ b/subjects/highest/README.md @@ -21,13 +21,13 @@ These methods have to be written: ```rust pub fn new(&[u32]) -> Self {} -pub fn List(&self) -> &[u32] {} +pub fn list(&self) -> &[u32] {} -pub fn Latest(&self) -> Option {} +pub fn latest(&self) -> Option {} -pub fn Highest(&self) -> Option {} +pub fn highest(&self) -> Option {} -pub fn Highest_Three(&self) -> Vec {} +pub fn highest_three(&self) -> Vec {} ``` ### Usage @@ -45,10 +45,10 @@ struct Numbers<'a> { fn main() { let expected = [30, 500, 20, 70]; let n = Numbers::new(&expected); - println!("{:?}", n.List()); - println!("{:?}", n.Highest()); - println!("{:?}", n.Latest()); - println!("{:?}", n.Highest_Three()); + println!("{:?}", n.list()); + println!("{:?}", n.highest()); + println!("{:?}", n.latest()); + println!("{:?}", n.highest_three()); } ``` diff --git a/subjects/matrix/README.md b/subjects/matrix/README.md index 953308a2..aec6fecd 100644 --- a/subjects/matrix/README.md +++ b/subjects/matrix/README.md @@ -8,13 +8,15 @@ Define a data structure to represent a matrix of any size and implement the basi - You have to use the definition of scalars done in the exercise: `lalgebra_scalar` -- Then define the associated function `identity` that returns the identity matrix of size n +- Define `new` that returns a matrix of size `1 x 1` -- Finally, define the associated function `zero` that returns a matrix of size `row x col` with all the positions filled by zeroes +- Then define the associated function `identity` that returns the identity matrix of size n +- Finally, define the associated function `zero` that returns a matrix of size `row x col` with all the positions filled by zeros + ### Notions -[Traits](https://doc.rust-lang.org/book/ch19-03-advanced-traits.html) +- [Traits](https://doc.rust-lang.org/book/ch19-03-advanced-traits.html) ### Expected Functions and Structure diff --git a/subjects/matrix_mult/README.md b/subjects/matrix_mult/README.md index 779a1bc5..cca64869 100644 --- a/subjects/matrix_mult/README.md +++ b/subjects/matrix_mult/README.md @@ -17,14 +17,14 @@ Define the matrix multiplication by implementing the std::ops::Mul for the type ### Expected Functions ```rust -impl Matrix { +impl Matrix {Esta errado o public, as funçoes row e col estao baralhadas com number of rows e number of colmns pub fn number_of_cols(&self) -> usize { } - pub fn rows(&self) -> usize { + pub fn number_of_row(&self, n: usize) -> usize { } - pub fn number_of_row(&self, n: usize) -> Vec { + pub fn rows(&self) -> Vec { } pub fn col(&self, n: usize) -> Vec { diff --git a/subjects/sales/README.md b/subjects/sales/README.md index fbaed37b..2b542182 100644 --- a/subjects/sales/README.md +++ b/subjects/sales/README.md @@ -5,11 +5,19 @@ In this exercise a shopping system will have to be created. There will be : - A store that will save all the products in it -- A cart that will have `items`, that the client will buy, and a `receipt` +- A cart that will have `items` that the client will buy, and a `receipt` This store is having a promotion, "Buy three and get one for free" (the free item must be the cheapest). The receipt must not present any value as 0, so the promotion must be a reduction to be applied to all items instead.(see the example) +You will have to implement for the Cart structure the following **functions**: + +- `new`, that will initialize the cart +- `insert_item`, that will receive a reference to `Store` and a `String`. Just like the name says you will + have to insert the item to the cart +- `generate_receipt`, that returns a vector of sorted floats. This function must generate the receipt just + like the example above, using the promotion. Also saving the result in the filed `receipt`. + ### Notions - [closures](https://doc.rust-lang.org/rust-by-example/fn/closures.html) @@ -17,8 +25,7 @@ any value as 0, so the promotion must be a reduction to be applied to all items ### Expected Function ```rust - -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct Store { pub products: Vec<(String, f32)>, } @@ -28,43 +35,34 @@ impl Store { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct Cart { // expected public fields } impl Cart { pub fn new() -> Cart {} pub fn insert_item(&mut self, s: &Store, ele: String) {} - pub fn get_prices(&self) -> Vec {} pub fn generate_receipt(&mut self) -> Vec {} } - ``` ### Example `[1.23, 3.12, 23.1]` -> the receipt will be `[1.17, 2.98, 22.07]` -So `1.17 + 2.98 + 22.07 == 3.12 + 23.1 + 0` +Because `1.17 + 2.98 + 22.07 == 0 + 3.12 + 23.1` This is a percentage calculation, and it can be applied to a set of three items. If the client purchase 9 items, the promotion will be applied, three for free, to all items -|--------------| |---------------| |---------------| + `[1.23, 23.1, 3.12, 9.75, 1.75, 23.75, 2.75, 1.64, 15.23]` -> the receipt will be `[1.16, 1.55, 1.65, 2.6, 2.94, 9.2, 14.38, 21.8, 22.42]` -|--------| |--------| |--------| + `[3.12, 9.75, 1.75, 23.75, 2.75, 1.64, 15.23]` -> the receipt will be `[1.54, 1.65, 2.59, 2.94, 9.18, 14.34, 22.36]` and so on... (hint: Closures is the way) -You will have to implement for the Cart structure the following **functions**: - -- `new`, that will initialize the cart -- `insert_item`, that will receive a reference to `Store` and a `String`. Just like the name says you will - have to insert the item to the cart -- `generate_receipt`, that returns a vector of sorted floats. This function must generate the receipt just - like the example above, using the promotion. Also saving the result in the filed `receipt`. ### Usage diff --git a/subjects/slices_to_map/README.md b/subjects/slices_to_map/README.md index b0d1a171..7f04ca10 100644 --- a/subjects/slices_to_map/README.md +++ b/subjects/slices_to_map/README.md @@ -2,7 +2,9 @@ ### Instructions: + Create a function that borrows two slices and returns a hashmap where the first slice represents the keys and the second represents the values. +- If the slices have different sizes, the function should return the hashmap with the size of the smallest list. ### Expected Function diff --git a/subjects/spelling/README.md b/subjects/spelling/README.md index 1f88663e..5c08bf5a 100644 --- a/subjects/spelling/README.md +++ b/subjects/spelling/README.md @@ -22,9 +22,6 @@ Only positive numbers will be tested. (Up to a million). - [patterns](https://doc.rust-lang.org/book/ch18-00-patterns.html) -### Dependencies - -rand = "0.7" ### Expected function diff --git a/subjects/talking/README.md b/subjects/talking/README.md index 99f8c097..1193ef79 100644 --- a/subjects/talking/README.md +++ b/subjects/talking/README.md @@ -8,7 +8,7 @@ His answers will be created by you following the rules below. - He answers "There is no need to yell, calm down!" if you yell at him, for example "LEAVE ME ALONE!" (it is considered yelling when the sentence is all written in capital letters). -- He answers "Sure" if you ask him something without yelling, for example "Is everything ok with you?" +- He answers "Sure." if you ask him something without yelling, for example "Is everything ok with you?" - He answers "Quiet, I am thinking!" if you yell a question at him. "HOW ARE YOU?" - He says "Just say something!" if you address him without actually saying anything. - He answers "Interesting" to anything else. diff --git a/subjects/traits/README.md b/subjects/traits/README.md index 8f44bde1..a19bf45e 100644 --- a/subjects/traits/README.md +++ b/subjects/traits/README.md @@ -6,10 +6,10 @@ Imagine you are designing a new video game and you have to create food that the There are two types of food for now: -- Fruit: increase the strength by 4 unit per each kilogram of fruit consumed. -- Meat: has the weight in kilograms -> `weight_in_kg` (which is the weight of the whole piece) and the fat_content which corresponds to the percentage of the weight which is pure fat (the rest is consider protein) each kilogram of protein gives 4 units of `strenght` and each kilogram of fat gives 9 units of `strength`. +- Fruit: increase the strength by 4 units per each kilogram of fruit consumed. +- Meat: has the weight in kilograms `weight_in_kg` (which is the weight of the whole piece) and the `fat_content` which corresponds to the percentage of the weight which is pure fat (the rest is considered protein) each kilogram of protein gives 4 units of `strength` and each kilogram of fat gives 9 units of `strength`. -Define the `Food` trait for `Fruit` and `Meat`. The method require method `gives()` represents the energy that the food provides. +Define the `Food` trait for `Fruit` and `Meat`. The required method `gives()` represents the energy that the food provides. Implement the `std::fmt::Display` trait for `Player` structure in a way that when using the template `{}` inside a println! macro it will print: @@ -17,6 +17,12 @@ Implement the `std::fmt::Display` trait for `Player` structure in a way that whe - In the second line the strength, score and the money - In the third line the weapons +### Notions + +- [Traits](https://doc.rust-lang.org/book/ch10-02-traits.html) + + + ### Expected Functions and Structures ```rust @@ -45,7 +51,7 @@ impl Player { } pub trait Food { - fn gives(&self) -> u32; + fn gives(&self) -> f64; } impl Food for Fruit { diff --git a/subjects/unwrap_or_expect/README.md b/subjects/unwrap_or_expect/README.md index 5ad1f0bb..c50c9393 100644 --- a/subjects/unwrap_or_expect/README.md +++ b/subjects/unwrap_or_expect/README.md @@ -8,11 +8,11 @@ return a tuple with a string, stating the error, and a vector with the elements The objective is to execute the `odd_to_even` function and handle the error returned by it. -Create the following functions which receives a vector : +Create the following functions which receive a vector: -- `expect` which returns the error adding the string "ERROR" +- `expect` which returns the error adding the string "ERROR " - `unwrap_or` which in case of error returns an empty vector -- `unwrap_err` which returns error if its `Ok` and returns the +- `unwrap_err` which panics if the value is `Ok` and returns the string containing the error in case of `Err` - `unwrap` which unwraps the `Result` - `unwrap_or_else` which in case of error returns the vector of elements that caused the error