Browse Source

saving proofreading final exam first part

pull/765/head
Chris 3 years ago
parent
commit
348649c54a
  1. 15
      subjects/display_table/README.md
  2. 24
      subjects/filter_table/README.md
  3. 45
      subjects/lunch_queue/README.md
  4. 10
      subjects/matrix_display/README.md
  5. 32
      subjects/queens/README.md

15
subjects/display_table/README.md

@ -2,30 +2,35 @@
### Instructions ### Instructions
- Implement the std::fmt::Display trait for the structure table so 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 doesn't allow to center exactly it must alight 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 doees not allow to center exactly, it must descend slightly to the right.
- Note: If the table is empty `println!` must not print anything. - Note: If the table is empty `println!` must not print anything.
- Define the associated function `new` that create a new empty table. - Define the associated function `new` which creates a new empty table.
- Define the method function `add_row` that adds a new row to the table created from a slice of strings. - Define the method function `add_row` which adds a new row to the table created from a slice of strings.
### Expected function ### Expected functions and Structures
```rust ```rust
#[derive(Clone, Debug, PartialEq)]
pub struct Table { pub struct Table {
pub headers: Vec<String>, pub headers: Vec<String>,
pub body: Vec<Vec<String>>, pub body: Vec<Vec<String>>,
} }
impl fmt::Display for Table { impl fmt::Display for Table {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
}
} }
impl Table { impl Table {
pub fn new() -> Table { pub fn new() -> Table {
}
}
pub fn add_row(&mut self, row: &[String]) { pub fn add_row(&mut self, row: &[String]) {
} }
} }
``` ```

24
subjects/filter_table/README.md

@ -2,23 +2,24 @@
### Instructions ### Instructions
- Define the functions: - Define the **functions**:
- new: creates a new empty table. - new: which creates a new empty table.
- add_rows: 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: that receives a closure that receives a `&str` and returns a `bool` value:
- filter_cols returns a table with all the columns that yielded true when applied to the header. - filter_cols: which receives a closure which receives a `&str` and returns a `bool` value:
- filter_rows: that 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_cols returns a table with all the columns that yielded true when applied to the header.
### Expected function - 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.
### Expected functions and Structures
```rust ```rust
#[derive(Clone, Debug, PartialEq)]
pub struct Table { pub struct Table {
pub headers: Vec<String>, pub headers: Vec<String>,
pub body: Vec<Vec<String>>, pub body: Vec<Vec<String>>,
@ -26,9 +27,11 @@ pub struct Table {
impl Table { impl Table {
pub fn new() -> Table { pub fn new() -> Table {
} }
pub fn add_row(&mut self, row: &[String]) { pub fn add_row(&mut self, row: &[String]) {
} }
pub fn filter_col(&self, filter: ) -> Option<Self> { pub fn filter_col(&self, filter: ) -> Option<Self> {
@ -36,6 +39,7 @@ impl Table {
} }
pub fn filter_row(&self, col_name: &str, filter: ) -> Option<Self> { pub fn filter_row(&self, col_name: &str, filter: ) -> Option<Self> {
} }
} }
``` ```

45
subjects/lunch_queue/README.md

@ -2,23 +2,27 @@
### Instructions ### Instructions
You will have to create an API to organize a queue of people. An API will have to be created to organize a queue of people.
Using the given code create the following functions: Using the given code declare the following functions:
- `new` that will initialize the `Queue`. - `new` which will initialize the `Queue`
- `add` that receives the person's information, so it can be added to the `Queue` - `add` which receives the person's information, so it can be added to the `Queue`
- `invert_queue` that invert the queue of persons - `invert_queue` which inverts the queue of persons
- `rm`, that will remove the person that finished ordering their food. - `rm`, which will remove the person who finished ordering their food.
The method for organizing the manipulation of a data structure should be a 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)
FIFO (first in first out) process. This function should return a tuple wrapped in an `Option` - `search`, which returns a tuple with the information of a given person `id`
with the information of that person
- `search`, that return 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`. 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. Do not forget that this will be a recursion type and it must point to `None` if there is no persons.
### Expected Function ### 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
```rust ```rust
pub struct Queue { pub struct Queue {
@ -44,7 +48,7 @@ impl Queue {
### Usage ### Usage
Here is a program to test your function Here is a program to test your function:
```rust ```rust
fn main() { fn main() {
@ -61,7 +65,8 @@ fn main() {
println!("removed {:?}", list.rm()); println!("removed {:?}", list.rm());
println!("list {:?}", list); println!("list {:?}", list);
println!("invert {:?}", list.invert_queue()); list.invert_queue();
println!("invert {:?}", list);
} }
``` ```
@ -74,15 +79,7 @@ Some(("Marie", 20))
Some(("Alice", 35)) Some(("Alice", 35))
None None
removed Some(("Marie", 20)) removed Some(("Marie", 20))
removed Some(("Monica", 15)) list Queue { node: Some(Person { name: "Alice", discount: 35, next_person: Some(Person { name: "Ana", discount: 5, next_person: Some(Person { name: "Monica", discount: 15, next_person: None }) }) }) }
list Queue { node: Some(Person { name: "Alice", discount: 35, next_person: Some(Person { name: "Ana", discount: 5, next_person: None }) }) } 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 }) }) }) }
inverted list Queue { node: Some(Person { name: "Ana", discount: 5, next_person: Some(Person { name: "Alice", discount: 35, next_person: None }) }) }
student@ubuntu:~/[[ROOT]]/test$ student@ubuntu:~/[[ROOT]]/test$
``` ```
### Notions
- https://doc.rust-lang.org/rust-by-example/custom_types/enum.html
- https://doc.rust-lang.org/book/ch15-01-box.html
- https://doc.rust-lang.org/std/option/
- https://doc.rust-lang.org/book/ch15-01-box.html

10
subjects/matrix_display/README.md

@ -4,19 +4,23 @@
Use the Matrix struct given in the [expected struct](#expected-functions-and-struct) and implement the `std::fmt::Display` trait so it prints the matrix like in the [usage](#usage). Use the Matrix struct given in the [expected struct](#expected-functions-and-struct) and implement the `std::fmt::Display` trait so it prints the matrix like in the [usage](#usage).
You will also have to implement the associated function `new` that creates a matrix from a slice of slices. The associated function `new` that creates a matrix from a slice of slices also has to be implemented.
### Expected Functions and Struct ### Expected Functions and Struct
```rust ```rust
pub struct Matrix(pub Vec<Vec<i32>>); pub struct Matrix(pub Vec<Vec<i32>>);
pub fn new(slice: &[&[i32]]) -> Self { impl Matrix {
pub fn new(slice: &[&[i32]]) -> Self {
}
} }
use std::fmt; use std::fmt;
impl fmt::Display for Matrix { impl fmt::Display for Matrix {
} }
``` ```
@ -25,8 +29,6 @@ impl fmt::Display for Matrix {
Here is a possible program to test your function Here is a possible program to test your function
```rust ```rust
use matrix_display::*;
fn main() { fn main() {
let matrix = Matrix::new(&[&[1, 2, 3], &[4, 5, 6], &[7, 8, 9]]); let matrix = Matrix::new(&[&[1, 2, 3], &[4, 5, 6], &[7, 8, 9]]);
println!("{}", matrix); println!("{}", matrix);

32
subjects/queens/README.md

@ -2,23 +2,21 @@
### Instructions ### Instructions
In a chess game, a queen can attack pieces which are on the same row, In a chess game, a queen can attack pieces which are on the same row, column, or diagonal.
column, or diagonal.
Your purpose in this exercise is to find out if two queens can attack The purpose of this exercise is to find out if two queens can attack each other using the same rules.
each other using the same rules.
The chess board will be represented as an 8 by 8 array. The chess board will be represented as an 8 by 8 array.
So, given the position of the two queens on a chess board, you will have to 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 implement the function `can_attack` in the given struct `Queen` with
the purpose of finding out if the two queens can attack each other or not. the purpose of finding out whether the two queens can attack each other or not.
For this to be possible, you will also have to implement the struct `ChessPosition` For this to be possible, you will also have to implement the struct `ChessPosition`
with the function `new` that will allow you to verify if the position is valid or not. If the position is valid it will return that position and if it is invalid it will return `None`. 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`.
So if you are told that the white queen is at (2, 3) and the black queen is at (5, 6), For example, if the white queen is at (2, 3) and the black queen is at (5, 6),
then you would know you have got a set-up like so: then the set-up would be like so:
``` ```
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@ -33,26 +31,30 @@ _ _ _ _ _ _ _ _
In this case, the two queens can attack each other because both pieces share a diagonal. In this case, the two queens can attack each other because both pieces share a diagonal.
### Expected Function ### Expected Function and Structures
```rust ```rust
#[derive(Debug)] #[derive(Debug)]
pub struct ChessPosition { pub struct ChessPosition {
rank: i32, pub rank: i32,
file: i32, pub file: i32,
} }
#[derive(Debug)] #[derive(Debug)]
pub struct Queen { pub struct Queen {
position: ChessPosition, pub position: ChessPosition,
} }
impl ChessPosition { impl ChessPosition {
pub fn new(rank: i32, file: i32) -> Option<Self> {} pub fn new(rank: i32, file: i32) -> Option<Self> {
}
} }
impl Queen { impl Queen {
pub fn can_attack(&self, other: &Queen) -> bool {} pub fn can_attack(&self, other: &Queen) -> bool {
}
} }
``` ```
@ -61,8 +63,6 @@ impl Queen {
Here is a possible program to test your function : Here is a possible program to test your function :
```rust ```rust
use queens::queens;
fn main() { fn main() {
let white_queen = Queen::new(ChessPosition::new(2, 2).unwrap()); let white_queen = Queen::new(ChessPosition::new(2, 2).unwrap());
let black_queen = Queen::new(ChessPosition::new(0, 4).unwrap()); let black_queen = Queen::new(ChessPosition::new(0, 4).unwrap());

Loading…
Cancel
Save