diff --git a/subjects/display_table/README.md b/subjects/display_table/README.md index 1e61d7ef5..ec768a50f 100644 --- a/subjects/display_table/README.md +++ b/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: diff --git a/subjects/display_table/main.rs b/subjects/display_table/main.rs index 72389813f..58de80ee4 100644 --- a/subjects/display_table/main.rs +++ b/subjects/display_table/main.rs @@ -1,3 +1,5 @@ +use display_table::*; + fn main() { let mut table = Table::new(); println!("{}", table); diff --git a/subjects/dress_code/main.rs b/subjects/dress_code/main.rs index 2e4d1b219..62f4f78a9 100644 --- a/subjects/dress_code/main.rs +++ b/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, ...")) + ); } diff --git a/subjects/filter_table/README.md b/subjects/filter_table/README.md index 09d09aa7c..3f6fe6ec6 100644 --- a/subjects/filter_table/README.md +++ b/subjects/filter_table/README.md @@ -41,33 +41,35 @@ impl Table { Here is a possible program to test your function: ```rust -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)); +use filter_table::*; - let filter_philips = |lastname: &str| lastname == "Philips"; - println!("{:?}", table.filter_row("Last Name", filter_philips)); +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)); } ``` diff --git a/subjects/filter_table/main.rs b/subjects/filter_table/main.rs index 060f0beee..05ea74784 100644 --- a/subjects/filter_table/main.rs +++ b/subjects/filter_table/main.rs @@ -1,3 +1,5 @@ +use filter_table::*; + fn main() { let mut table = Table::new(); table.headers = vec![ diff --git a/subjects/flat_tree/README.md b/subjects/flat_tree/README.md index 73a0da427..0051e9ae9 100644 --- a/subjects/flat_tree/README.md +++ b/subjects/flat_tree/README.md @@ -17,21 +17,25 @@ pub fn flatten_tree>(tree: &BTreeSet) -> Vec { Here is a possible program to test your function: ```rust -fn main() { - let mut tree = BTreeSet::new(); - tree.insert(34); - tree.insert(0); - tree.insert(9); - tree.insert(30); - println!("{:?}", flatten_tree(&tree)); +use flat_tree::*; +use std::collections::BTreeSet; - let mut tree = BTreeSet::new(); - tree.insert("Slow"); - tree.insert("kill"); - tree.insert("will"); - tree.insert("Horses"); - println!("{:?}", flatten_tree(&tree)); +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)); } + ``` And its output: diff --git a/subjects/flat_tree/main.rs b/subjects/flat_tree/main.rs index abf25c3f7..f216ce904 100644 --- a/subjects/flat_tree/main.rs +++ b/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); diff --git a/subjects/inv_pyramid/README.md b/subjects/inv_pyramid/README.md index d9ee108d5..ba28f26d7 100644 --- a/subjects/inv_pyramid/README.md +++ b/subjects/inv_pyramid/README.md @@ -34,6 +34,8 @@ fn inv_pyramid(v: String, i: u32) -> Vec {} 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); diff --git a/subjects/inv_pyramid/main.rs b/subjects/inv_pyramid/main.rs index d8b2df663..621cd7af6 100644 --- a/subjects/inv_pyramid/main.rs +++ b/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); diff --git a/subjects/lunch_queue/README.md b/subjects/lunch_queue/README.md index d69e84f9d..ed3bbd605 100644 --- a/subjects/lunch_queue/README.md +++ b/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); diff --git a/subjects/lunch_queue/main.rs b/subjects/lunch_queue/main.rs index f28bb3715..10e7f543f 100644 --- a/subjects/lunch_queue/main.rs +++ b/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); diff --git a/subjects/matrix_determinant/README.md b/subjects/matrix_determinant/README.md index 43589006b..76b680693 100644 --- a/subjects/matrix_determinant/README.md +++ b/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) ); } ``` diff --git a/subjects/matrix_determinant/main.rs b/subjects/matrix_determinant/main.rs index 30ecbdab1..33ef98afc 100644 --- a/subjects/matrix_determinant/main.rs +++ b/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) ); } diff --git a/subjects/matrix_display/README.md b/subjects/matrix_display/README.md index 141c35d53..a5757d46b 100644 --- a/subjects/matrix_display/README.md +++ b/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: diff --git a/subjects/matrix_display/main.rs b/subjects/matrix_display/main.rs index 34c270e1c..cbc34ec57 100644 --- a/subjects/matrix_display/main.rs +++ b/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); diff --git a/subjects/negative_spelling/main.rs b/subjects/negative_spelling/main.rs new file mode 100644 index 000000000..2e4d1b219 --- /dev/null +++ b/subjects/negative_spelling/main.rs @@ -0,0 +1,6 @@ +use negative_spelling::*; + +fn main() { + println!("{}", negative_spell(-1234)); + println!("{}", negative_spell(100)); +} diff --git a/subjects/nextprime/README.md b/subjects/nextprime/README.md index c320e1aad..2eb7e7efa 100644 --- a/subjects/nextprime/README.md +++ b/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 : diff --git a/subjects/nextprime/main.rs b/subjects/nextprime/main.rs index 2354ee4ab..4ec8bfc78 100644 --- a/subjects/nextprime/main.rs +++ b/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)); diff --git a/subjects/partial_sums/README.md b/subjects/partial_sums/README.md index 17ffb2b0f..d3a7209d9 100644 --- a/subjects/partial_sums/README.md +++ b/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 : {:?}", diff --git a/subjects/partial_sums/main.rs b/subjects/partial_sums/main.rs index eb2cd31e8..545488b4a 100644 --- a/subjects/partial_sums/main.rs +++ b/subjects/partial_sums/main.rs @@ -1,3 +1,5 @@ +use partial_sums::*; + fn main() { println!( "Partial sums of [5, 18, 3, 23] is : {:?}", diff --git a/subjects/previousprime/README.md b/subjects/previousprime/README.md index 196bdbc6c..8cd5c1294 100644 --- a/subjects/previousprime/README.md +++ b/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)); } diff --git a/subjects/previousprime/main.rs b/subjects/previousprime/main.rs index b07667296..8629b6fc6 100644 --- a/subjects/previousprime/main.rs +++ b/subjects/previousprime/main.rs @@ -1,3 +1,5 @@ +use previousprime::*; + fn main() { println!("The previous prime number before 34 is: {}", prev_prime(34)); } diff --git a/subjects/queens/README.md b/subjects/queens/README.md index 6cbae6c18..3af78077d 100644 --- a/subjects/queens/README.md +++ b/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: diff --git a/subjects/queens/main.rs b/subjects/queens/main.rs index f07f24e18..17acf0588 100644 --- a/subjects/queens/main.rs +++ b/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()); diff --git a/subjects/reverse_it/README.md b/subjects/reverse_it/README.md index 38443afb6..4d59fed44 100644 --- a/subjects/reverse_it/README.md +++ b/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)); diff --git a/subjects/reverse_it/main.rs b/subjects/reverse_it/main.rs index f5464a8ce..e6af2f1ff 100644 --- a/subjects/reverse_it/main.rs +++ b/subjects/reverse_it/main.rs @@ -1,3 +1,5 @@ +use reverse_it::reverse_it; + fn main() { println!("{}", reverse_it(123)); println!("{}", reverse_it(-123)); diff --git a/subjects/scytale_decoder/README.md b/subjects/scytale_decoder/README.md index 15163bf3b..3591fc7ca 100644 --- a/subjects/scytale_decoder/README.md +++ b/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 { 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)); diff --git a/subjects/scytale_decoder/main.rs b/subjects/scytale_decoder/main.rs index 796301449..67461332b 100644 --- a/subjects/scytale_decoder/main.rs +++ b/subjects/scytale_decoder/main.rs @@ -1,3 +1,5 @@ +use scytale_decoder::*; + fn main() { println!( "\"sec yCtoadle\" size=2 -> {:?}",