diff --git a/subjects/division_and_remainder/README.md b/subjects/division_and_remainder/README.md index 25f24e0035..d74a7049ee 100644 --- a/subjects/division_and_remainder/README.md +++ b/subjects/division_and_remainder/README.md @@ -14,7 +14,7 @@ pub fn divide(x: i32, y: i32) -> (i32, i32) { Here is a program to test your function ```rust -use division_and_remainder::divide; +use division_and_remainder::*; fn main() { let x = 9; diff --git a/subjects/fibonacci2/README.md b/subjects/fibonacci2/README.md index 1ed26827f0..e1707f278a 100644 --- a/subjects/fibonacci2/README.md +++ b/subjects/fibonacci2/README.md @@ -5,8 +5,8 @@ Complete the body of the **function** `fibonacci`. ```rust - pub fn fibonacci(n: u32) -> u32 { - } +pub fn fibonacci(n: u32) -> u32 { +} ``` This function receives a number `n` and returns the `n`th number in the fibonacci series. @@ -18,13 +18,29 @@ The Fibonacci Series starts like this: 0, 1, 1, 2, 3, 5, 8, 13 etc... Here is a possible test for your function: ```rust -use fibonacci2::fibonacci; +use fibonacci2::*; fn main() { - println!("The element in the position {} in fibonacci series is {}",2, fibonacci(2)); - println!("The element in the position {} in fibonacci series is {}",4, fibonacci(4)); - println!("The element in the position {} in fibonacci series is {}",22, fibonacci(22)); - println!("The element in the position {} in fibonacci series is {}", 20, fibonacci(20)); + println!( + "The element in the position {} in fibonacci series is {}", + 2, + fibonacci(2) + ); + println!( + "The element in the position {} in fibonacci series is {}", + 4, + fibonacci(4) + ); + println!( + "The element in the position {} in fibonacci series is {}", + 22, + fibonacci(22) + ); + println!( + "The element in the position {} in fibonacci series is {}", + 20, + fibonacci(20) + ); } ``` diff --git a/subjects/find_factorial/README.md b/subjects/find_factorial/README.md index b89c63ef4e..f1187d93b9 100644 --- a/subjects/find_factorial/README.md +++ b/subjects/find_factorial/README.md @@ -17,10 +17,10 @@ Example: the factorial of 6 (written 6!) is 1 \* 2 \* 3 \* 4 \* 5 \* 6 = 720. ### Usage -Here is a possible program to test your function : +Here is a possible program to test your function: ```rust -use find_factorial::factorial; +use find_factorial::*; fn main() { println!("The factorial of 0 = {}", factorial(0)); diff --git a/subjects/groceries/README.md b/subjects/groceries/README.md index bbc377192e..78d7fe770f 100644 --- a/subjects/groceries/README.md +++ b/subjects/groceries/README.md @@ -6,12 +6,11 @@ Create a **function** named `insert`, that inserts a new element at the end of t Create another **function** named `at_index` that returns the value found at the index passed as an argument. - ```rust pub fn insert(vec: &mut Vec, val: String) { } -pub fn at_index(vec: &Vec, index: usize) -> String { +pub fn at_index(slice: &[String], index: usize) -> &str { } ``` @@ -20,21 +19,18 @@ pub fn at_index(vec: &Vec, index: usize) -> String { Here is a possible program to test your function: ```rust -use groceries::{insert, at_index}; +use groceries::*; fn main() { - let mut groceries = vec![ - "yogurt".to_string(), - "panettone".to_string(), - "bread".to_string(), - "cheese".to_string(), - ]; - insert(&mut groceries, String::from("nuts")); - println!("The groceries list contains {:?}", &groceries); - println!( - "The second element of the grocery list is {:?}", - at_index(&groceries, 1) - ); + let mut groceries = vec![ + "yogurt".to_string(), + "panettone".to_string(), + "bread".to_string(), + "cheese".to_string(), + ]; + insert(&mut groceries, String::from("nuts")); + println!("groceries = {:?}", &groceries); + println!("groceries[1] = {:?}", at_index(&groceries, 1)); } ``` @@ -42,12 +38,12 @@ And its output: ```console $ cargo run -The groceries list contains ["yogurt", "panettone", "bread", "cheese", "nuts"] -The second element of the grocery list is "panettone" +groceries = ["yogurt", "panettone", "bread", "cheese", "nuts"] +groceries[1] = "panettone" $ ``` ### Notions - [Common Collections](https://doc.rust-lang.org/stable/book/ch08-00-common-collections.html) -- [Vectors](https://doc.rust-lang.org/stable/book/ch08-01-vectors.html) \ No newline at end of file +- [Vectors](https://doc.rust-lang.org/stable/book/ch08-01-vectors.html) diff --git a/subjects/looping/README.md b/subjects/looping/README.md index bf87cf3231..b709cae6b8 100644 --- a/subjects/looping/README.md +++ b/subjects/looping/README.md @@ -17,7 +17,7 @@ Answer: The letter e - [Module std::io](https://doc.rust-lang.org/std/io/index.html) - [loop](https://doc.rust-lang.org/std/keyword.loop.html) -### UsageĀ  +### Usage ```console $ cargo run diff --git a/subjects/matrix_transposition/README.md b/subjects/matrix_transposition/README.md index d98cd00c83..9ffad76120 100644 --- a/subjects/matrix_transposition/README.md +++ b/subjects/matrix_transposition/README.md @@ -27,8 +27,7 @@ The transposition of a matrix, switches the columns to rows, and the rows to col Here is a possible program to test your function ```rust -use matrix_transposition::transpose; -use matrix_transposition::Matrix; +use matrix_transposition::*; fn main() { let matrix = Matrix((1, 3), (4, 5)); diff --git a/subjects/reverse_string/README.md b/subjects/reverse_string/README.md index d49e9c9d0d..3fe13f0455 100644 --- a/subjects/reverse_string/README.md +++ b/subjects/reverse_string/README.md @@ -4,7 +4,6 @@ Create a **function** named `rev_str` that takes a `&str` as a parameter, and returns a `String` with its letters reversed. - ```rust pub fn rev_str(input: &str) -> String { } @@ -15,7 +14,7 @@ pub fn rev_str(input: &str) -> String { Here is a possible program to test your function : ```rust -use reverse_string::rev_str; +use reverse_string::*; fn main() { println!("{}", rev_str("Hello, world!")); @@ -43,4 +42,4 @@ $ - [Strings](https://doc.rust-lang.org/rust-by-example/std/str.html) - [Primitive Type str](https://doc.rust-lang.org/std/primitive.str.html) - [Primtive Type char](https://doc.rust-lang.org/std/primitive.char.html) -- [Module std::string](https://doc.rust-lang.org/std/string/index.html) \ No newline at end of file +- [Module std::string](https://doc.rust-lang.org/std/string/index.html) diff --git a/subjects/scalar/README.md b/subjects/scalar/README.md index fbcbc69b11..19338a315c 100644 --- a/subjects/scalar/README.md +++ b/subjects/scalar/README.md @@ -11,8 +11,7 @@ Create the following **functions**, which each accept two parameters: - `rem`, which returns the remainder of the division between two 32bit values > You will need to figure out the exact data types for the parameters **and** the return values. - There are some hints in the example. - +> There are some hints in the example. ```rust pub fn sum(a: X, b: X) -> X { @@ -43,23 +42,27 @@ use scalar::*; fn main() { // sum - println!("sum : {}", sum(234, 2)); // 'sum : 236' - println!("sum : {}", sum(1, 255)); // 'ERROR: attempt to add with overflow' + println!("sum: {}", sum(234, 2)); // 'sum: 236' + println!("sum: {}", sum(1, 255)); // 'ERROR: attempt to add with overflow' + // diff - println!("diff : {}", diff(234, 2)); // 'diff : 232' - println!("diff : {}", diff(-32768, 32766)); // 'ERROR: attempt to subtract with overflow' + println!("diff: {}", diff(234, 2)); // 'diff: 232' + println!("diff: {}", diff(-32768, 32766)); // 'ERROR: attempt to subtract with overflow' + // product - println!("pro : {}", pro(23, 2)); // 'pro : 46' - println!("pro : {}", pro(-128, 2)); // 'ERROR: attempt to multiply with overflow' + println!("pro: {}", pro(23, 2)); // 'pro: 46' + println!("pro: {}", pro(-128, 2)); // 'ERROR: attempt to multiply with overflow' + // quotient - println!("quo : {}", quo(22.0, 2.0));// 'quo : 11' - println!("quo : {}", quo(-128.23, 2.0));// 'quo : -64.115' + println!("quo: {}", quo(22.0, 2.0)); // 'quo: 11' + println!("quo: {}", quo(-128.23, 2.0)); // 'quo: -64.115' + // remainder - println!("rem : {}", rem(22.0, 2.0));// 'rem : 0' - println!("rem : {}", rem(-128.23, 2.0));// 'rem : -0.22999573' + println!("rem: {}", rem(22.0, 2.0)); // 'rem: 0' + println!("rem: {}", rem(-128.23, 2.0)); // 'rem: -0.22999573' } ``` ### Notions -- [Data Types](https://doc.rust-lang.org/book/ch03-02-data-types.html) \ No newline at end of file +- [Data Types](https://doc.rust-lang.org/book/ch03-02-data-types.html) diff --git a/subjects/speed_transformation/README.md b/subjects/speed_transformation/README.md index 0e40a429fc..903c764d72 100644 --- a/subjects/speed_transformation/README.md +++ b/subjects/speed_transformation/README.md @@ -14,12 +14,12 @@ pub fn km_per_hour_to_meters_per_second(km_h: f64) -> f64 { ### Usage ```rust -use speed_transformation::km_per_hour_to_meters_per_second; +use speed_transformation::*; fn main() { - let km_h = 100.0; - let m_s = km_per_hour_to_meters_per_second(km_h); - println!("{} km/h is equivalent to {} m/s", km_h, m_s); + let km_h = 100.0; + let m_s = km_per_hour_to_meters_per_second(km_h); + println!("{} km/h is equivalent to {} m/s", km_h, m_s); } ``` diff --git a/subjects/temperature_conv/README.md b/subjects/temperature_conv/README.md index d498076051..6b68d2789e 100644 --- a/subjects/temperature_conv/README.md +++ b/subjects/temperature_conv/README.md @@ -22,8 +22,8 @@ pub fn celsius_to_fahrenheit(c: f64) -> f64 { use temperature_conv::*; fn main() { - println!("{} F = {} C", -459.67, fahrenheit_to_celsius(-459.67)); - println!("{} C = {} F", 0.0, celsius_to_fahrenheit(0.0)); + println!("{} F = {} C", -459.67, fahrenheit_to_celsius(-459.67)); + println!("{} C = {} F", 0.0, celsius_to_fahrenheit(0.0)); } ``` diff --git a/subjects/tuples_refs/README.md b/subjects/tuples_refs/README.md index d3ec808039..5a9881477d 100644 --- a/subjects/tuples_refs/README.md +++ b/subjects/tuples_refs/README.md @@ -10,10 +10,10 @@ pub fn id(student: &Student) -> u32 { } -pub fn first_name(student: &Student) -> String { +pub fn first_name(student: &Student) -> &str { } -pub fn last_name(student: &Student) -> String { +pub fn last_name(student: &Student) -> &str { } ``` @@ -25,11 +25,10 @@ Here is a program to test your functions use tuples_refs::*; fn main() { - let student = Student(20, "Pedro".to_string(), "Domingos".to_string()); - println!("Student: {:?}", student); - println!("Student first name: {}", first_name(&student)); - println!("Student last name: {}", last_name(&student)); - println!("Student Id: {}", id(&student)); + let student = Student(20, "Pedro".to_string(), "Domingos".to_string()); + println!("Student's first name: {}", first_name(&student)); + println!("Student's last name: {}", last_name(&student)); + println!("Student's id: {}", id(&student)); } ``` @@ -37,10 +36,9 @@ And its output: ```console $ cargo run -Student: Student(20, "Pedro", "Domingos") -Student first name: Pedro -Student last name: Domingos -Student Id: 20 +Student's first name: Pedro +Student's last name: Domingos +Student's id: 20 $ ```