Browse Source

Merge pull request #1084 from 01-edu/update-roman_numbers_iter-and-rpn-c-555

Update roman numbers iter and rpn c 555
pull/1097/head
MSilva95 3 years ago committed by GitHub
parent
commit
d9219bf3a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 52
      subjects/roman_numbers_iter/README.md
  2. 16
      subjects/rpn/README.md

52
subjects/roman_numbers_iter/README.md

@ -2,50 +2,18 @@
### Instructions ### 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. Implement the `Iterator` trait for the `RomanNumber` type. You should use the code from the previous exercise roman_numbers.
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 {
}
```
### Notions ### Notions
- https://doc.rust-lang.org/std/iter/trait.IntoIterator.html - [Trait Iterator](https://doc.rust-lang.org/std/iter/trait.Iterator.html)
- https://doc.rust-lang.org/std/iter/index.html
### Expected Functions ### Expected Functions
```rust ```rust
use roman_numbers::{RomanDigit, RomanNumber}; //...
impl IntoIterator for &RomanNumber { impl Iterator for RomanNumber {}
}
impl IntoIterator for &mut RomanNumber {
}
impl IntoIterator for RomanNumber {
}
``` ```
### Usage ### Usage
@ -56,12 +24,10 @@ Here is a program to test your function.
use roman_numbers::RomanNumber; use roman_numbers::RomanNumber;
fn main() { fn main() {
let number = RomanNumber::from(15); let mut number = RomanNumber::from(15);
for digit in &number {
println!("{:?}", digit);
}
println!("{:?}", number); println!("{:?}", number);
println!("{:?}", number.next());
} }
``` ```
@ -69,9 +35,7 @@ And its output
```console ```console
$ cargo run $ cargo run
RomanNumber([X, X, X, I, I]) RomanNumber([X, V])
RomanNumber([I, X]) Some(RomanNumber([X, V, I]))
RomanNumber([X, L, V])
RomanNumber([Nulla])
$ $
``` ```

16
subjects/rpn/README.md

@ -2,17 +2,14 @@
### Instructions ### Instructions
Write a **program** which takes a `string` which contains an equation written in `Reverse Polish Notation` (RPN) as its first argument, 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:
which evaluates the equation, and which prints the result on the standard output followed by a newline (`'\n'`).
`Reverse Polish Notation` is a mathematical notation in which every operator follows all of its operands. In RPN, - 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.
every operator encountered evaluates the previous 2 operands, and the result of this operation then becomes the first of - If the `string` has extra spaces it is still considered valid.
the two operands for the subsequent operator. Operands and operators must be spaced by at least one space.
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. The following operators must be implemented : `+`, `-`, `*`, `/`, and `%`.
If the `string` has extra spaces it is still considered valid.
All the given operands must fit in a `i64`. 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 ### Usage
````console ```console
$ cargo run "1 2 * 3 * 4 +" $ cargo run "1 2 * 3 * 4 +"
10 10
$ cargo run "1 2 3 4 +" $ cargo run "1 2 3 4 +"
@ -67,4 +64,3 @@ $ cargo run " 1 3 * 2 -"
$ cargo run " 1 3 * ksd 2 -" $ cargo run " 1 3 * ksd 2 -"
Error Error
``` ```
````

Loading…
Cancel
Save