Browse Source

Merge pull request #1099 from 01-edu/update-exams-exercises-rust-public-c-562

Update exams exercises rust
1122-buz-zinga
David Mata 2 years ago committed by GitHub
parent
commit
236249c52f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      subjects/blood_types_s/README.md
  2. 33
      subjects/brackets_matching/README.md
  3. 10
      subjects/brain_fuck/README.md
  4. 6
      subjects/display_table/README.md
  5. 16
      subjects/filter_table/README.md
  6. 2
      subjects/flat_tree/README.md
  7. 47
      subjects/lunch_queue/README.md
  8. BIN
      subjects/matrix_determinant/determinant-of-a-3x3-matrix-formula-3.png
  9. 23
      subjects/queens/README.md
  10. 5
      subjects/tuples_refs/README.md

5
subjects/blood_types_s/README.md

@ -33,12 +33,12 @@ pub enum Antigen {
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
enum RhFactor {
pub enum RhFactor {
Positive,
Negative,
}
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
pub struct BloodType {
pub antigen: Antigen,
pub rh_factor: RhFactor,
@ -52,6 +52,7 @@ impl BloodType {
}
pub fn recipients(&self) -> Vec<Self> {
}
}
```

33
subjects/brackets_matching/README.md

@ -2,24 +2,35 @@
### Instructions
Write a program that takes an undefined number of `string` in arguments. For each argument, if the expression is correctly bracketed, the program prints on the standard output `OK` followed by a newline (`'\n'`), otherwise it prints `Error` followed by a newline.
Write a `program` that takes an undefined number of `string` in arguments. For each argument, if the expression is correctly bracketed, the program prints on the standard output `OK` followed by a newline (`'\n'`), otherwise it prints `Error` followed by a newline.
Symbols considered as brackets are parentheses `(` and `)`, square brackets `[` and `]` and curly braces `{` and `}`. Every other symbols are simply ignored.
An opening bracket must always be closed by the good closing bracket in the correct order. A `string` which does not contain any bracket is considered as a correctly bracketed `string`.
An opening bracket must always be closed by the good closing bracket in the correct order. A `string` which does not contain any bracket is considered as a correctly bracketed.
If there is no argument, the program must print nothing.
For receiving arguments from the command line you should use something like:
```rust
fn main() {
let args: Vec<String> = std::env::args().collect();
//...
}
```
### Usage
```console
$ go run . '(johndoe)' | cat -e
OK$
$ go run . '([)]' | cat -e
Error$
$ go run . '' '{[(0 + 0)(1 + 1)](3*(-1)){()}}' | cat -e
OK$
OK$
$ go run .
$
$ cargo run '(johndoe)' | cat -e
OK
$ cargo run '([)]' | cat -e
Error
$ cargo run
$ cargo run '' '{[(0 + 0)(1 + 1)](3*(-1)){()}}' | cat -e
OK
OK
```

10
subjects/brain_fuck/README.md

@ -5,7 +5,7 @@
Write a `Brainfuck` interpreter program.
The source code will be given as first parameter.
The code will always be valid, with less than 4096 operations.
`Brainfuck` is a minimalist language. It consists of an array of bytes (in this exercice 2048 bytes) all initialized with zero, and with a pointer to its first byte.
`Brainfuck` is a minimalist language. It consists of an array of bytes (in this exercise 2048 bytes) all initialized with zero, and with a pointer to its first byte.
Every operator consists of a single character :
@ -22,11 +22,11 @@ Any other character is a comment.
For receiving arguments from the command line you should use something like:
```rust
fn main() {
let args: Vec<String> = std::env::args().collect();
fn main() {
let args: Vec<String> = std::env::args().collect();
brain_fuck(&args[1]);
}
brain_fuck(&args[1]);
}
```

6
subjects/display_table/README.md

@ -2,9 +2,9 @@
### Instructions
- Implement the `std::fmt::Display` trait for the structure table so that the table is printed like in the **[Usage](#usage)**. The length of each column must adjust to the longest element of the column and the element must be centered in the "cell" when possible. If the length of the element doees not allow to center exactly, it must descend slightly to the right.
- Implement the `std::fmt::Display` trait for the structure table so that the table is printed like in the **[Usage](#usage)**. The length of each column must adjust to the longest element of the column and the element must be centered in the "cell" when possible. If the length of the element does not allow to center exactly, it must be offset slightly to the left.
- Note: If the table is empty `println!` must not print anything.
- Note: If the table is empty (does not have a header), `println!` must not print anything.
- Define the associated function `new` which creates a new empty table.
@ -22,7 +22,7 @@ pub struct Table {
impl fmt::Display for Table {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
}
}
}
impl Table {

16
subjects/filter_table/README.md

@ -4,17 +4,13 @@
- Define the **functions**:
- new: which creates a new empty table.
- `new`: which creates a new empty table.
- add_rows: which adds a new row to the table from a slice of strings.
- `add_rows`: which adds a new row to the table from a slice of strings.
- filter_cols: which receives a closure which receives a `&str` and returns a `bool` value:
- `filter_cols`: which receives a closure and returns a table with all the columns that yielded true when applying that closure. The closure will receive a `&str` and return a `bool` value.
- filter_cols returns a table with all the columns that yielded true when applied to the header.
- filter_rows: which receives a closure that receives a `&str` and returns a `bool` value
- filter_rows returns a table with all the columns that yielded true when applied to the elements of the selected column.
- `filter_rows`: which receives a closure and returns a table with all the rows that yielded true when applied to the elements of the selected column. The closure will receive a `&str` and return a `bool` value.
### Expected functions and Structures
@ -34,11 +30,11 @@ impl Table {
}
pub fn filter_col(&self, filter: ) -> Option<Self> {
pub fn filter_col(&self, filter: T) -> Option<Self> {
}
pub fn filter_row(&self, col_name: &str, filter: ) -> Option<Self> {
pub fn filter_row(&self, col_name: &str, filter: T) -> Option<Self> {
}
}

2
subjects/flat_tree/README.md

@ -1,4 +1,4 @@
## flat_rust
## flat_tree
### Instructions

47
subjects/lunch_queue/README.md

@ -2,27 +2,21 @@
### Instructions
An API will have to be created to organize a queue of people.
You will need to create an *API* which will organize a queue of people, so that a program can organize a queue of people.
Using the given code declare the following functions:
The program requires the following functionsAdd the following associated functions to the `Queue` structure:
- `new` which will initialize the `Queue`
- `add` which receives the person's information, so it can be added to the `Queue`
- `invert_queue` which inverts the queue of persons
- `rm`, which will remove the person who finished ordering their food.
- `new`: which will initialize the `Queue`.
- `add`: which receives a person's information, to add them to the `Queue`.
- `invert_queue`: which reverses the queue.
- `rm`: which will remove the person who finished ordering their food. The removal should respect the FIFO method (first in first out. The function should return the removed person.
The removal should respect a FIFO system (first in first out). This function should return a tuple wrapped in an `Option` with the information of the removed person (check the usage)
- `search`, which returns a tuple with the information of a given person `id`
- `search`: which returns a tuple with the information of a given person `id`
You must also create a type called `Link`. This will be the connection of the structures `Queue` and `Person`.
Do not forget that this will be a recursion type and it must point to `None` if there is no persons.
### Notions
- [enum](https://doc.rust-lang.org/rust-by-example/custom_types/enum.html)
- [Box](https://doc.rust-lang.org/book/ch15-01-box.html)
- [std::option](https://doc.rust-lang.org/std/option/)
### Expected Function adn Structures
### Expected Function and Structures
```rust
pub struct Queue {
@ -37,12 +31,21 @@ pub struct Person {
}
impl Queue {
pub fn new() -> Queue {}
pub fn add(&mut self, t: String, name: String) {}
pub fn invert_queue(&mut self) {}
pub fn rm(&mut self) -> Option<String> {}
pub fn search(&self) -> Option<(String, String)> {}
pub fn new() -> Queue {
}
pub fn add(&mut self, t: String, name: String) {
}
pub fn invert_queue(&mut self) {
}
pub fn rm(&mut self) -> Option<String> {
}
pub fn search(&mut self, ) -> Option<(String, String)> {
}
}
```
@ -83,3 +86,9 @@ list Queue { node: Some(Person { name: "Alice", discount: 35, next_person: Some(
invert Queue { node: Some(Person { name: "Monica", discount: 15, next_person: Some(Person { name: "Ana", discount: 5, next_person: Some(Person { name: "Alice", discount: 35, next_person: None }) }) }) }
$
```
### Notions
- [enum](https://doc.rust-lang.org/rust-by-example/custom_types/enum.html)
- [Box](https://doc.rust-lang.org/book/ch15-01-box.html)
- [std::option](https://doc.rust-lang.org/std/option/)

BIN
subjects/matrix_determinant/determinant-of-a-3x3-matrix-formula-3.png

diff.bin_not_shown

After

Width:  |  Height:  |  Size: 14 KiB

23
subjects/queens/README.md

@ -2,21 +2,18 @@
### Instructions
In a chess game, a queen can attack pieces which are on the same row, column, or diagonal.
In a chess game, a queen can attack pieces which are on the same rank (row), file (column), or diagonal.
The purpose of this exercise is to find out if two queens can attack each other using the same rules.
The purpose of this exercise is to find out if two queens can attack each other.
The chess board will be represented as an 8 by 8 array.
The position of a chess piece on a chessboard will be represented by the struct `ChessPosition`. You must implement the associated function `new` which will return the position if it is valid, otherwise it will return `None`.
> Remember, chessboards have 8 files and 8 ranks (each from 0 to 7).
So, given the position of the two queens on a chess board, you will have to
implement the function `can_attack` in the given struct `Queen` with
the purpose of finding out whether the two queens can attack each other or not.
You will create the `Queen` struct with the associate function `can_attack`, which will return `true` if the queens can attack each other or not. You also need to implement the function `new` which creates a new `Queen` with a `ChessPosition`.
For this to be possible, you will also have to implement the struct `ChessPosition`
with the function `new`. This will allow you to verify if the position is valid or not. If the position is valid it will return that position, otherwise it will return `None`.
### Example
For example, if the white queen is at (2, 3) and the black queen is at (5, 6),
then the set-up would be like so:
If the white queen is at (2, 3) and the black queen is at (5, 6), then the set-up would be like the below. In this case, the two queens can attack each other because both pieces share a diagonal:
```
_ _ _ _ _ _ _ _
@ -29,8 +26,6 @@ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
```
In this case, the two queens can attack each other because both pieces share a diagonal.
### Expected Function and Structures
```rust
@ -52,6 +47,10 @@ impl ChessPosition {
}
impl Queen {
pub fn new(position: ChessPosition) -> Self {
}
pub fn can_attack(&self, other: &Queen) -> bool {
}

5
subjects/tuples_refs/README.md

@ -17,11 +17,6 @@ pub fn last_name(student: &Student) -> String {
}
```
### Dependencies
meval = "0.2"
### Usage
Here is a program to test your functions

Loading…
Cancel
Save