Compare commits

...

6 Commits

  1. 4
      subjects/adding/README.md
  2. 13
      subjects/adding_twice/README.md
  3. 11
      subjects/closures/README.md
  4. 20
      subjects/get_products/README.md
  5. 23
      subjects/highest/README.md
  6. 46
      subjects/sales/README.md

4
subjects/adding/README.md

@ -2,8 +2,8 @@
### Instructions
Create the function `add_curry` that returns a closure.
The purpose is to curry the add method to create more variations.
Create the function `add_curry`, which returns a closure.
The purpose is to 'curry' the add method to create more variations.
### Usage

13
subjects/adding_twice/README.md

@ -2,14 +2,11 @@
### Instructions
In this exercise you will have to reuse your `add_curry` function (copy and paste it directly in your lib.rs file).
Then you have to create the function `twice` using closures, this function will
take a function f(x) as parameter and return a function f(f(x)).
So, the purpose of this function is to add two times the value in `add_curry` to the original value.
You'll need to reuse your `add_curry` function. Copy and paste it directly into your `lib.rs` file.
### Notions
Now create a function named `twice` using closures. This function will take a function `f(x)` as parameter, and return a function `f(f(x))`.
- [higher order function](https://doc.rust-lang.org/rust-by-example/fn/hof.html#higher-order-functions)
So, the purpose of this function is to add two times the value in `add_curry` to the original value.
### Expected functions
@ -57,3 +54,7 @@ The value is 67
The value is -57
$
```
### Notions
- [higher order function](https://doc.rust-lang.org/rust-by-example/fn/hof.html#higher-order-functions)

11
subjects/closures/README.md

@ -2,12 +2,7 @@
### Instructions
Using closures and iterators create a **function**, `first_fifty_even_square` that returns the first 50 even numbers squared.
in a `Vec<i32>`.
### Notions
[Iterators and Closures](https://doc.rust-lang.org/book/ch13-00-functional-features.html)
Using closures and iterators create a **function**, that returns the first 50 even numbers squared in a `Vec<i32>`.
### Expected Functions
@ -39,3 +34,7 @@ $ cargo run
All elements in [4, 16, 36, ..., 10000], len = 50
$
```
### Notions
[Iterators and Closures](https://doc.rust-lang.org/book/ch13-00-functional-features.html)

20
subjects/get_products/README.md

@ -2,18 +2,16 @@
### Instructions
Create a function `get_products` that takes a vector of integers, and returns a vector of the products
of each index. For this exercise to be correct you will have to return the product of every index
except the current one.
Create a function named `get_products` that takes a vector of integers, and returns a vector of the products of each index.
Examples: [1,2,3,4]
You'll need to return the product of every index
except the current one.
- for the number `1` we get `2*3*4 = 24`
- for the number `3` we get `1*2*4 = 8`
### Example:
For `[1,2,3,4]`, we get:
### Notions
- [Trait iterator](https://doc.rust-lang.org/std/iter/trait.Iterator.html)
- for the number `1` we get `2*3*4 = 24`.
- for the number `3` we get `1*2*4 = 8`.
### Expected functions
@ -44,3 +42,7 @@ $ cargo run
[84, 12, 28, 21]
$
```
### Notions
- [Trait iterator](https://doc.rust-lang.org/std/iter/trait.Iterator.html)

23
subjects/highest/README.md

@ -2,19 +2,14 @@
### Instructions
In this exercise a `Numbers` struct will be given.
In this exercise, a `Numbers` struct will be given.
These methods have to be written:
- `new` create a new instance of Number.
- `List` that returns an `array` with every number in the struct.
- `Latest` that returns an `Option<u32>` with the last added number.
- `Highest` that return an `Option<u32>` with the highest number from the list.
- `Highest_Three` that returns a `Vec<u32>` with the three highest numbers.
### Notions
- [Trait iterator](https://doc.rust-lang.org/std/iter/trait.Iterator.html)
These methods have to be written for it:
- `new`: create a new instance of `Number`.
- `List`: which returns an `array` with every number in the struct.
- `Latest`: which returns an `Option<u32>` with the last added number.
- `Highest`: which returns an `Option<u32>` with the highest number from the list.
- `Highest_Three`: which returns a `Vec<u32>` with the three highest numbers.
### Expected functions
@ -62,3 +57,7 @@ Some(70)
[500, 70, 30]
$
```
### Notions
- [Trait iterator](https://doc.rust-lang.org/std/iter/trait.Iterator.html)

46
subjects/sales/README.md

@ -2,25 +2,17 @@
### Instructions
In this exercise a shopping system will have to be created. There will be :
Your going to make a shopping system. It will have a store where the products will be saved, and a cart which will contain items from which a receipt will be generated.
- A store that will save all the products in it
- A cart that will have `items` that the client will buy, and a `receipt`
**"Buy three, get one free".**
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)
The store is having a promotion. The cheapest of three items will be free. But there is a problem with the printer interface, it cannot receive any zero values. We can create a workaround. We will reduce all of the values in the cart by a small amount to show the correct total price. You can see the example to see how it works.
You will have to implement for the Cart structure the following **functions**:
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)
- `new`: that will initialize the cart.
- `insert_item`: will receive a reference to `Store` and a `String`. Just like the name says, it will insert the item to the cart.
- `generate_receipt`: returns a vector of sorted floats. This function must generate the receipt just like the example below, using the promotion. AIt should save the result in the `receipt` field.
### Expected Function
@ -48,20 +40,24 @@ impl Cart {
### Example
`[1.23, 3.12, 23.1]` -> the receipt will be `[1.17, 2.98, 22.07]`
Because `1.17 + 2.98 + 22.07 == 0 + 3.12 + 23.1`
```
[1.23, 3.12, 23.1]` => `[1.17, 2.98, 22.07]
```
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
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 purchases 9 items, they will receive three for free, with the discount applied 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]`
```
[1.23, 23.1, 3.12, 9.75, 1.75, 23.75, 2.75, 1.64, 15.23] => [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]`
```
[3.12, 9.75, 1.75, 23.75, 2.75, 1.64, 15.23] => [1.54, 1.65, 2.59, 2.94, 9.18, 14.34, 22.36]
```
and so on... (hint: Closures is the way)
> Hint: Closures are the way.
### Usage
@ -99,3 +95,7 @@ Store { products: [("product A", 1.23), ("product B", 23.1), ("product C", 3.12)
Cart { items: [("product A", 1.23), ("product B", 23.1), ("product C", 3.12)], receipt: [1.17, 2.98, 22.07] }
$
```
### Notions
- [closures](https://doc.rust-lang.org/rust-by-example/fn/closures.html)

Loading…
Cancel
Save