Browse Source

fix(piscine-rust): add crates to exercises

pull/2283/head
miguel 6 months ago committed by MSilva95
parent
commit
166a10990f
  1. 59
      subjects/display_table/README.md
  2. 2
      subjects/display_table/main.rs
  3. 8
      subjects/dress_code/main.rs
  4. 54
      subjects/filter_table/README.md
  5. 2
      subjects/filter_table/main.rs
  6. 30
      subjects/flat_tree/README.md
  7. 3
      subjects/flat_tree/main.rs
  8. 2
      subjects/inv_pyramid/README.md
  9. 2
      subjects/inv_pyramid/main.rs
  10. 4
      subjects/lunch_queue/README.md
  11. 2
      subjects/lunch_queue/main.rs
  12. 4
      subjects/matrix_determinant/README.md
  13. 4
      subjects/matrix_determinant/main.rs
  14. 7
      subjects/matrix_display/README.md
  15. 2
      subjects/matrix_display/main.rs
  16. 6
      subjects/negative_spelling/main.rs
  17. 3
      subjects/nextprime/README.md
  18. 2
      subjects/nextprime/main.rs
  19. 2
      subjects/partial_sums/README.md
  20. 2
      subjects/partial_sums/main.rs
  21. 2
      subjects/previousprime/README.md
  22. 2
      subjects/previousprime/main.rs
  23. 4
      subjects/queens/README.md
  24. 2
      subjects/queens/main.rs
  25. 2
      subjects/reverse_it/README.md
  26. 2
      subjects/reverse_it/main.rs
  27. 5
      subjects/scytale_decoder/README.md
  28. 2
      subjects/scytale_decoder/main.rs

59
subjects/display_table/README.md

@ -1,6 +1,6 @@
## display_table
### Instructions
### Instructions
Define the `Table` struct below, and implement the associated functions `new` and `add_row`. You can see how they should work from the usage.
@ -38,35 +38,38 @@ impl Table {
Here is a possible program to test your function:
```rust
use display_table::*;
fn main() {
let mut table = Table::new();
println!("{}", table);
table.headers = vec![
String::from("Model"),
String::from("Piece N°"),
String::from("In Stock"),
String::from("Description"),
];
table.add_row(&[
String::from("model 1"),
String::from("43-EWQE304"),
String::from("30"),
String::from("Piece for x"),
]);
table.add_row(&[
String::from("model 2"),
String::from("98-QCVX5433"),
String::from("100000000"),
String::from("-"),
]);
table.add_row(&[
String::from("model y"),
String::from("78-NMNH"),
String::from("60"),
String::from("nothing"),
]);
println!("{}", table);
let mut table = Table::new();
println!("{}", table);
table.headers = vec![
String::from("Model"),
String::from("Piece N°"),
String::from("In Stock"),
String::from("Description"),
];
table.add_row(&[
String::from("model 1"),
String::from("43-EWQE304"),
String::from("30"),
String::from("Piece for x"),
]);
table.add_row(&[
String::from("model 2"),
String::from("98-QCVX5433"),
String::from("100000000"),
String::from("-"),
]);
table.add_row(&[
String::from("model y"),
String::from("78-NMNH"),
String::from("60"),
String::from("nothing"),
]);
println!("{}", table);
}
```
And its output:

2
subjects/display_table/main.rs

@ -1,3 +1,5 @@
use display_table::*;
fn main() {
let mut table = Table::new();
println!("{}", table);

8
subjects/dress_code/main.rs

@ -1,6 +1,8 @@
use negative_spelling::*;
use dress_code::*;
fn main() {
println!("{}", negative_spell(-1234));
println!("{}", negative_spell(100));
println!(
"My outfit will be: {:?}",
choose_outfit(Some(0), Ok("Dear friend, ..."))
);
}

54
subjects/filter_table/README.md

@ -41,33 +41,35 @@ impl Table {
Here is a possible program to test your function:
```rust
use filter_table::*;
fn main() {
let mut table = Table::new();
table.headers = vec![
"Name".to_string(),
"Last Name".to_string(),
"ID Number".to_string(),
];
table.add_row(&[
"Adam".to_string(),
"Philips".to_string(),
"123456789".to_string(),
]);
table.add_row(&[
"Adamaris".to_string(),
"Shelby".to_string(),
"1111123456789".to_string(),
]);
table.add_row(&[
"Ackerley".to_string(),
"Philips".to_string(),
"123456789".to_string(),
]);
let filter_names = |col: &str| col == "Name";
println!("{:?}", table.filter_col(filter_names));
let filter_philips = |lastname: &str| lastname == "Philips";
println!("{:?}", table.filter_row("Last Name", filter_philips));
let mut table = Table::new();
table.headers = vec![
"Name".to_string(),
"Last Name".to_string(),
"ID Number".to_string(),
];
table.add_row(&[
"Adam".to_string(),
"Philips".to_string(),
"123456789".to_string(),
]);
table.add_row(&[
"Adamaris".to_string(),
"Shelby".to_string(),
"1111123456789".to_string(),
]);
table.add_row(&[
"Ackerley".to_string(),
"Philips".to_string(),
"123456789".to_string(),
]);
let filter_names = |col: &str| col == "Name";
println!("{:?}", table.filter_col(filter_names));
let filter_philips = |lastname: &str| lastname == "Philips";
println!("{:?}", table.filter_row("Last Name", filter_philips));
}
```

2
subjects/filter_table/main.rs

@ -1,3 +1,5 @@
use filter_table::*;
fn main() {
let mut table = Table::new();
table.headers = vec![

30
subjects/flat_tree/README.md

@ -17,21 +17,25 @@ pub fn flatten_tree<T: ToOwned<Owned = T>>(tree: &BTreeSet<T>) -> Vec<T> {
Here is a possible program to test your function:
```rust
use flat_tree::*;
use std::collections::BTreeSet;
fn main() {
let mut tree = BTreeSet::new();
tree.insert(34);
tree.insert(0);
tree.insert(9);
tree.insert(30);
println!("{:?}", flatten_tree(&tree));
let mut tree = BTreeSet::new();
tree.insert("Slow");
tree.insert("kill");
tree.insert("will");
tree.insert("Horses");
println!("{:?}", flatten_tree(&tree));
let mut tree = BTreeSet::new();
tree.insert(34);
tree.insert(0);
tree.insert(9);
tree.insert(30);
println!("{:?}", flatten_tree(&tree));
let mut tree = BTreeSet::new();
tree.insert("Slow");
tree.insert("kill");
tree.insert("will");
tree.insert("Horses");
println!("{:?}", flatten_tree(&tree));
}
```
And its output:

3
subjects/flat_tree/main.rs

@ -1,3 +1,6 @@
use flat_tree::*;
use std::collections::BTreeSet;
fn main() {
let mut tree = BTreeSet::new();
tree.insert(34);

2
subjects/inv_pyramid/README.md

@ -34,6 +34,8 @@ fn inv_pyramid(v: String, i: u32) -> Vec<String> {}
Here is a program to test your function
```rust
use inv_pyramid::*;
fn main() {
let a = inv_pyramid(String::from("#"), 1);
let b = inv_pyramid(String::from("a"), 2);

2
subjects/inv_pyramid/main.rs

@ -1,3 +1,5 @@
use inv_pyramid::*;
fn main() {
let a = inv_pyramid(String::from("#"), 1);
let b = inv_pyramid(String::from("a"), 2);

4
subjects/lunch_queue/README.md

@ -2,7 +2,7 @@
### Instructions
You will need to create an *API*, so that a program can organize a queue of people.
You will need to create an _API_, so that a program can organize a queue of people.
The program requires the following functions. Add them as associated functions to the `Queue` structure:
@ -52,6 +52,8 @@ impl Queue {
Here is a program to test your function:
```rust
use lunch_queue::*;
fn main() {
let mut list = Queue::new();
list.add(String::from("Marie"), 20);

2
subjects/lunch_queue/main.rs

@ -1,3 +1,5 @@
use lunch_queue::*;
fn main() {
let mut list = Queue::new();
list.add(String::from("Marie"), 20);

4
subjects/matrix_determinant/README.md

@ -36,12 +36,14 @@ pub fn matrix_determinant(matrix: [[isize; 3]; 3]) -> isize {
Here is a program to test your function:
```rs
use matrix_determinant::*;
fn main() {
let matrix = [[1, 2, 4], [2, -1, 3], [4, 0, 1]];
println!(
"The determinant of the matrix:\n|1 2 4|\n|2 -1 3| = {}\n|4 0 1|",
matrix_determinant(matr)
matrix_determinant(matrix)
);
}
```

4
subjects/matrix_determinant/main.rs

@ -1,8 +1,10 @@
use matrix_determinant::*;
fn main() {
let matrix = [[1, 2, 4], [2, -1, 3], [4, 0, 1]];
println!(
"The determinant of the matrix:\n|1 2 4|\n|2 -1 3| = {}\n|4 0 1|",
matrix_determinant(matr)
matrix_determinant(matrix)
);
}

7
subjects/matrix_display/README.md

@ -31,10 +31,13 @@ impl fmt::Display for Matrix {
Here is a possible program to test your function
```rust
use matrix_display::*;
fn main() {
let matrix = Matrix::new(&[&[1, 2, 3], &[4, 5, 6], &[7, 8, 9]]);
println!("{}", matrix);
let matrix = Matrix::new(&[&[1, 2, 3], &[4, 5, 6], &[7, 8, 9]]);
println!("{}", matrix);
}
```
And it's output:

2
subjects/matrix_display/main.rs

@ -1,3 +1,5 @@
use matrix_display::*;
fn main() {
let matrix = Matrix::new(&[&[1, 2, 3], &[4, 5, 6], &[7, 8, 9]]);
println!("{}", matrix);

6
subjects/negative_spelling/main.rs

@ -0,0 +1,6 @@
use negative_spelling::*;
fn main() {
println!("{}", negative_spell(-1234));
println!("{}", negative_spell(100));
}

3
subjects/nextprime/README.md

@ -21,10 +21,13 @@ pub fn next_prime(nbr: u64) -> u64 {
Here is a possible program to test your function :
```rust
use nextprime::*;
fn main() {
println!("The next prime after 4 is: {}", next_prime(4));
println!("The next prime after 11 is: {}", next_prime(11));
}
```
And its output :

2
subjects/nextprime/main.rs

@ -1,3 +1,5 @@
use nextprime::*;
fn main() {
println!("The next prime after 4 is: {}", next_prime(4));
println!("The next prime after 11 is: {}", next_prime(11));

2
subjects/partial_sums/README.md

@ -49,6 +49,8 @@ pub fn parts_sums(arr: &[u64]) -> Vec<64>{
Here is a program to test your function:
```rs
use partial_sums::*;
fn main() {
println!(
"Partial sums of [5, 18, 3, 23] is : {:?}",

2
subjects/partial_sums/main.rs

@ -1,3 +1,5 @@
use partial_sums::*;
fn main() {
println!(
"Partial sums of [5, 18, 3, 23] is : {:?}",

2
subjects/previousprime/README.md

@ -19,6 +19,8 @@ pub fn prev_prime(nbr: u64) -> u64 {
Here is a possible program to test your function :
```rust
use previousprime::*;
fn main() {
println!("The previous prime number before 34 is: {}", prev_prime(34));
}

2
subjects/previousprime/main.rs

@ -1,3 +1,5 @@
use previousprime::*;
fn main() {
println!("The previous prime number before 34 is: {}", prev_prime(34));
}

4
subjects/queens/README.md

@ -7,6 +7,7 @@ In a chess game, a queen can attack pieces which are on the same rank (row), fil
The purpose of this exercise is to find out if two queens can attack each other.
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).
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`.
@ -62,6 +63,8 @@ impl Queen {
Here is a possible program to test your function :
```rust
use queens::*;
fn main() {
let white_queen = Queen::new(ChessPosition::new(2, 2).unwrap());
let black_queen = Queen::new(ChessPosition::new(0, 4).unwrap());
@ -79,6 +82,7 @@ fn main() {
white_queen.can_attack(&black_queen)
);
}
```
And its output:

2
subjects/queens/main.rs

@ -1,3 +1,5 @@
use queens::*;
fn main() {
let white_queen = Queen::new(ChessPosition::new(2, 2).unwrap());
let black_queen = Queen::new(ChessPosition::new(0, 4).unwrap());

2
subjects/reverse_it/README.md

@ -16,6 +16,8 @@ pub fn reverse_it(v: i32) -> String {
Here is a program to test your function,
```rust
use reverse_it::reverse_it;
fn main() {
println!("{}", reverse_it(123));
println!("{}", reverse_it(-123));

2
subjects/reverse_it/main.rs

@ -1,3 +1,5 @@
use reverse_it::reverse_it;
fn main() {
println!("{}", reverse_it(123));
println!("{}", reverse_it(-123));

5
subjects/scytale_decoder/README.md

@ -4,7 +4,7 @@
Create a **function** which decode a scytale cipher (also known as spartan cipher).
In practice, it is represented by a strip wrapped around a cylinder. The message is written across the loops of the strip (not along the strip). The message becomes *coded* if the radius of the cylinder changes, or the strip is removed from the cylinder.
In practice, it is represented by a strip wrapped around a cylinder. The message is written across the loops of the strip (not along the strip). The message becomes _coded_ if the radius of the cylinder changes, or the strip is removed from the cylinder.
Your function will receive a `String` representing the ciphered message, and a `u32` representing the number of letters by turn of the strip around the cylinder.
@ -23,7 +23,6 @@ Your function will receive a `String` representing the ciphered message, and a `
**letters_per_turn 4:** `"scytale Code"` -> `"steoca dylCe"`
```console
------------------------------------------
|s| |c| |y|
@ -45,6 +44,8 @@ pub fn scytale_decoder(s: String, letters_per_turn: u32) -> Option<String> {
Here is a program to test your function
```rust
use scytale_decoder::*;
fn main() {
println!("\"sec yCtoadle\" size=2 -> {:?}",
scytale_decoder("sec yCtoadle".to_string(), 2));

2
subjects/scytale_decoder/main.rs

@ -1,3 +1,5 @@
use scytale_decoder::*;
fn main() {
println!(
"\"sec yCtoadle\" size=2 -> {:?}",

Loading…
Cancel
Save