mirror of https://github.com/01-edu/public.git
fix(piscine-rust): add crates to exercises
This commit is contained in:
parent
1aa3484757
commit
166a10990f
|
@ -38,6 +38,8 @@ impl Table {
|
||||||
Here is a possible program to test your function:
|
Here is a possible program to test your function:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
use display_table::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut table = Table::new();
|
let mut table = Table::new();
|
||||||
println!("{}", table);
|
println!("{}", table);
|
||||||
|
@ -67,6 +69,7 @@ fn main() {
|
||||||
]);
|
]);
|
||||||
println!("{}", table);
|
println!("{}", table);
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
And its output:
|
And its output:
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use display_table::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut table = Table::new();
|
let mut table = Table::new();
|
||||||
println!("{}", table);
|
println!("{}", table);
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use negative_spelling::*;
|
use dress_code::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("{}", negative_spell(-1234));
|
println!(
|
||||||
println!("{}", negative_spell(100));
|
"My outfit will be: {:?}",
|
||||||
|
choose_outfit(Some(0), Ok("Dear friend, ..."))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,8 @@ impl Table {
|
||||||
Here is a possible program to test your function:
|
Here is a possible program to test your function:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
use filter_table::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut table = Table::new();
|
let mut table = Table::new();
|
||||||
table.headers = vec![
|
table.headers = vec![
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use filter_table::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut table = Table::new();
|
let mut table = Table::new();
|
||||||
table.headers = vec![
|
table.headers = vec![
|
||||||
|
|
|
@ -17,6 +17,9 @@ pub fn flatten_tree<T: ToOwned<Owned = T>>(tree: &BTreeSet<T>) -> Vec<T> {
|
||||||
Here is a possible program to test your function:
|
Here is a possible program to test your function:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
use flat_tree::*;
|
||||||
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut tree = BTreeSet::new();
|
let mut tree = BTreeSet::new();
|
||||||
tree.insert(34);
|
tree.insert(34);
|
||||||
|
@ -32,6 +35,7 @@ fn main() {
|
||||||
tree.insert("Horses");
|
tree.insert("Horses");
|
||||||
println!("{:?}", flatten_tree(&tree));
|
println!("{:?}", flatten_tree(&tree));
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
And its output:
|
And its output:
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
use flat_tree::*;
|
||||||
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut tree = BTreeSet::new();
|
let mut tree = BTreeSet::new();
|
||||||
tree.insert(34);
|
tree.insert(34);
|
||||||
|
|
|
@ -34,6 +34,8 @@ fn inv_pyramid(v: String, i: u32) -> Vec<String> {}
|
||||||
Here is a program to test your function
|
Here is a program to test your function
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
use inv_pyramid::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let a = inv_pyramid(String::from("#"), 1);
|
let a = inv_pyramid(String::from("#"), 1);
|
||||||
let b = inv_pyramid(String::from("a"), 2);
|
let b = inv_pyramid(String::from("a"), 2);
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use inv_pyramid::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let a = inv_pyramid(String::from("#"), 1);
|
let a = inv_pyramid(String::from("#"), 1);
|
||||||
let b = inv_pyramid(String::from("a"), 2);
|
let b = inv_pyramid(String::from("a"), 2);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
### Instructions
|
### 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:
|
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:
|
Here is a program to test your function:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
use lunch_queue::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut list = Queue::new();
|
let mut list = Queue::new();
|
||||||
list.add(String::from("Marie"), 20);
|
list.add(String::from("Marie"), 20);
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use lunch_queue::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut list = Queue::new();
|
let mut list = Queue::new();
|
||||||
list.add(String::from("Marie"), 20);
|
list.add(String::from("Marie"), 20);
|
||||||
|
|
|
@ -36,12 +36,14 @@ pub fn matrix_determinant(matrix: [[isize; 3]; 3]) -> isize {
|
||||||
Here is a program to test your function:
|
Here is a program to test your function:
|
||||||
|
|
||||||
```rs
|
```rs
|
||||||
|
use matrix_determinant::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let matrix = [[1, 2, 4], [2, -1, 3], [4, 0, 1]];
|
let matrix = [[1, 2, 4], [2, -1, 3], [4, 0, 1]];
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"The determinant of the matrix:\n|1 2 4|\n|2 -1 3| = {}\n|4 0 1|",
|
"The determinant of the matrix:\n|1 2 4|\n|2 -1 3| = {}\n|4 0 1|",
|
||||||
matrix_determinant(matr)
|
matrix_determinant(matrix)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
|
use matrix_determinant::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let matrix = [[1, 2, 4], [2, -1, 3], [4, 0, 1]];
|
let matrix = [[1, 2, 4], [2, -1, 3], [4, 0, 1]];
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"The determinant of the matrix:\n|1 2 4|\n|2 -1 3| = {}\n|4 0 1|",
|
"The determinant of the matrix:\n|1 2 4|\n|2 -1 3| = {}\n|4 0 1|",
|
||||||
matrix_determinant(matr)
|
matrix_determinant(matrix)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,10 +31,13 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
And it's output:
|
And it's output:
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
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);
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
use negative_spelling::*;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("{}", negative_spell(-1234));
|
||||||
|
println!("{}", negative_spell(100));
|
||||||
|
}
|
|
@ -21,10 +21,13 @@ pub fn next_prime(nbr: u64) -> u64 {
|
||||||
Here is a possible program to test your function :
|
Here is a possible program to test your function :
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
use nextprime::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("The next prime after 4 is: {}", next_prime(4));
|
println!("The next prime after 4 is: {}", next_prime(4));
|
||||||
println!("The next prime after 11 is: {}", next_prime(11));
|
println!("The next prime after 11 is: {}", next_prime(11));
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
And its output :
|
And its output :
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use nextprime::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("The next prime after 4 is: {}", next_prime(4));
|
println!("The next prime after 4 is: {}", next_prime(4));
|
||||||
println!("The next prime after 11 is: {}", next_prime(11));
|
println!("The next prime after 11 is: {}", next_prime(11));
|
||||||
|
|
|
@ -49,6 +49,8 @@ pub fn parts_sums(arr: &[u64]) -> Vec<64>{
|
||||||
Here is a program to test your function:
|
Here is a program to test your function:
|
||||||
|
|
||||||
```rs
|
```rs
|
||||||
|
use partial_sums::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!(
|
println!(
|
||||||
"Partial sums of [5, 18, 3, 23] is : {:?}",
|
"Partial sums of [5, 18, 3, 23] is : {:?}",
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use partial_sums::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!(
|
println!(
|
||||||
"Partial sums of [5, 18, 3, 23] is : {:?}",
|
"Partial sums of [5, 18, 3, 23] is : {:?}",
|
||||||
|
|
|
@ -19,6 +19,8 @@ pub fn prev_prime(nbr: u64) -> u64 {
|
||||||
Here is a possible program to test your function :
|
Here is a possible program to test your function :
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
use previousprime::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("The previous prime number before 34 is: {}", prev_prime(34));
|
println!("The previous prime number before 34 is: {}", prev_prime(34));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use previousprime::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("The previous prime number before 34 is: {}", prev_prime(34));
|
println!("The previous prime number before 34 is: {}", prev_prime(34));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 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`.
|
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).
|
> 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`.
|
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 :
|
Here is a possible program to test your function :
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
use 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());
|
||||||
|
@ -79,6 +82,7 @@ fn main() {
|
||||||
white_queen.can_attack(&black_queen)
|
white_queen.can_attack(&black_queen)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
And its output:
|
And its output:
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use 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());
|
||||||
|
|
|
@ -16,6 +16,8 @@ pub fn reverse_it(v: i32) -> String {
|
||||||
Here is a program to test your function,
|
Here is a program to test your function,
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
use reverse_it::reverse_it;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("{}", reverse_it(123));
|
println!("{}", reverse_it(123));
|
||||||
println!("{}", reverse_it(-123));
|
println!("{}", reverse_it(-123));
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use reverse_it::reverse_it;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("{}", reverse_it(123));
|
println!("{}", reverse_it(123));
|
||||||
println!("{}", reverse_it(-123));
|
println!("{}", reverse_it(-123));
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
Create a **function** which decode a scytale cipher (also known as spartan cipher).
|
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.
|
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"`
|
**letters_per_turn 4:** `"scytale Code"` -> `"steoca dylCe"`
|
||||||
|
|
||||||
|
|
||||||
```console
|
```console
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
|s| |c| |y|
|
|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
|
Here is a program to test your function
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
use scytale_decoder::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("\"sec yCtoadle\" size=2 -> {:?}",
|
println!("\"sec yCtoadle\" size=2 -> {:?}",
|
||||||
scytale_decoder("sec yCtoadle".to_string(), 2));
|
scytale_decoder("sec yCtoadle".to_string(), 2));
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use scytale_decoder::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!(
|
println!(
|
||||||
"\"sec yCtoadle\" size=2 -> {:?}",
|
"\"sec yCtoadle\" size=2 -> {:?}",
|
||||||
|
|
Loading…
Reference in New Issue