diff --git a/subjects/roman_numbers_iter/README.md b/subjects/roman_numbers_iter/README.md index 4277708a..5596bf29 100644 --- a/subjects/roman_numbers_iter/README.md +++ b/subjects/roman_numbers_iter/README.md @@ -2,50 +2,18 @@ ### Instructions -Implement the `IntoIterator` trait for the `RomanNumber` type to enable using a for loop notation. This implementation must allow taking ownership, borrowing and borrowing mutably. - -1. Taking ownership (this consumes the RomanNumber) - -```rust -for digit in number { - ... -} -``` - -2. Borrowing immutably (this preserves the RomanNumber) - -```rust - for digit in &number { - - } -``` - -3. Borrowing mutably (this allow you to modify the RomanNumber without having to return the ownership) - -```rust - for digit in &mut number { - - } -``` +Implement the `Iterator` trait for the `RomanNumber` type. You should use the code from the previous exercise roman_numbers. ### Notions -- https://doc.rust-lang.org/std/iter/trait.IntoIterator.html -- https://doc.rust-lang.org/std/iter/index.html +- [Trait Iterator](https://doc.rust-lang.org/std/iter/trait.Iterator.html) ### Expected Functions ```rust -use roman_numbers::{RomanDigit, RomanNumber}; +//... -impl IntoIterator for &RomanNumber { -} - -impl IntoIterator for &mut RomanNumber { -} - -impl IntoIterator for RomanNumber { -} +impl Iterator for RomanNumber {} ``` ### Usage @@ -56,12 +24,10 @@ Here is a program to test your function. use roman_numbers::RomanNumber; fn main() { - let number = RomanNumber::from(15); + let mut number = RomanNumber::from(15); - for digit in &number { - println!("{:?}", digit); - } println!("{:?}", number); + println!("{:?}", number.next()); } ``` @@ -69,9 +35,7 @@ And its output ```console $ cargo run -RomanNumber([X, X, X, I, I]) -RomanNumber([I, X]) -RomanNumber([X, L, V]) -RomanNumber([Nulla]) +RomanNumber([X, V]) +Some(RomanNumber([X, V, I])) $ ``` diff --git a/subjects/rpn/README.md b/subjects/rpn/README.md index 9e3a5f6a..213dd90b 100644 --- a/subjects/rpn/README.md +++ b/subjects/rpn/README.md @@ -2,17 +2,14 @@ ### Instructions -Write a **program** which takes a `string` which contains an equation written in `Reverse Polish Notation` (RPN) as its first argument, -which evaluates the equation, and which prints the result on the standard output followed by a newline (`'\n'`). +Write a **program** which takes a `string` that contains an equation written in `Reverse Polish Notation` (RPN) as an argument. The **program** must evaluate the equation, and then: -`Reverse Polish Notation` is a mathematical notation in which every operator follows all of its operands. In RPN, -every operator encountered evaluates the previous 2 operands, and the result of this operation then becomes the first of -the two operands for the subsequent operator. Operands and operators must be spaced by at least one space. +- If the `string` is not valid or if there is not exactly one argument, `Error` must be printed on the standard output followed by a newline. +- If the `string` has extra spaces it is still considered valid. -The following operators must be implemented : `+`, `-`, `*`, `/`, and `%`. +`Reverse Polish Notation` is a mathematical notation in which every operator follows all of its operands. In RPN, every operator encountered evaluates the previous 2 operands, and the result of this operation then becomes the first of the two operands for the subsequent operator. Operands and operators must be spaced by at least one space. -If the `string` is not valid or if there is not exactly one argument, `Error` must be printed on the standard output followed by a newline. -If the `string` has extra spaces it is still considered valid. +The following operators must be implemented : `+`, `-`, `*`, `/`, and `%`. All the given operands must fit in a `i64`. @@ -55,7 +52,7 @@ For receiving arguments from the command line you should use something like: ### Usage -````console +```console $ cargo run "1 2 * 3 * 4 +" 10 $ cargo run "1 2 3 4 +" @@ -67,4 +64,3 @@ $ cargo run " 1 3 * 2 -" $ cargo run " 1 3 * ksd 2 -" Error ``` -````