diff --git a/subjects/division_and_remainder/README.md b/subjects/division_and_remainder/README.md index 71f58c97..525e4171 100644 --- a/subjects/division_and_remainder/README.md +++ b/subjects/division_and_remainder/README.md @@ -2,7 +2,15 @@ ### Instructions -Create a function divide that receives two i32 and returns a tuple in which the first element is the result of the integer division between the two numbers and the second is the remainder of the division. +Create a **function** `divide` that receives two i32 and returns a tuple in which the first element is the result of the integer division between the two numbers and the second is the remainder of the division. + +### Notions + +- [The Tuple Type](https://doc.rust-lang.org/stable/book/ch03-02-data-types.html?highlight=accessing%20a%20tuple#compound-types) + +- [Tuples](https://doc.rust-lang.org/rust-by-example/primitives/tuples.html) + +- [Tuple Structs without Named Fields](https://doc.rust-lang.org/stable/book/ch05-01-defining-structs.html?highlight=tuple#using-tuple-structs-without-named-fields-to-create-different-types) ### Expected Function @@ -14,10 +22,10 @@ pub fn divide(x: i32, y: i32) -> (i32, i32) { ### Usage -Here is a program to test you're function +Here is a program to test your function ```rust -use division_and_remainder::division_and_remainder; +use division_and_remainder::divide; fn main() { let x = 9; diff --git a/subjects/fibonacci2/README.md b/subjects/fibonacci2/README.md index 7cd2af06..5b06a394 100644 --- a/subjects/fibonacci2/README.md +++ b/subjects/fibonacci2/README.md @@ -2,12 +2,16 @@ ### Instructions -Complete the body of the function `fibonacci`. +Complete the body of the **function** `fibonacci`. -This functions receives a number n and returns the nth number in the fibonacci series. +This functions receives a number `n` and returns the nth number in the fibonacci series. -The Fibonacci Series starts like this: 0, 1, 1, 2, 3, 5, 8, 13... so fibonacci(2) = 1 and fibonnacci(4) = 3 +The Fibonacci Series starts like this: 0, 1, 1, 2, 3, 5, 8, 13 etc... +### Notions + +- [Primitives](https://doc.rust-lang.org/stable/rust-by-example/primitives.html) +- [Functions](https://doc.rust-lang.org/stable/rust-by-example/fn.html) ### Expected function @@ -42,4 +46,3 @@ The element in the position 22 in fibonacci series is 17711 The element in the position 20 in fibonacci series is 6765 student@ubuntu:~/[[ROOT]]/test$ ``` - diff --git a/subjects/find_factorial/README.md b/subjects/find_factorial/README.md index dfb88d15..183e78fe 100644 --- a/subjects/find_factorial/README.md +++ b/subjects/find_factorial/README.md @@ -2,7 +2,13 @@ ### Instruccions -Complete the function `factorial` to return the factorial of a given number +Complete the **function** `factorial` to return the factorial of a given number. + +As a reminder the factorial of a number is the product of all the integers from 1 to that number. + +Example: the factorial of 6 (written 6!) is 1*2*3*4*5*6 = 720. + +Do not forget the rules for 0 and 1. ### Expected Function diff --git a/subjects/groceries/README.md b/subjects/groceries/README.md index eeac4cb2..28c00fa5 100644 --- a/subjects/groceries/README.md +++ b/subjects/groceries/README.md @@ -2,13 +2,14 @@ ### Instructions -Create a function called `insert` that inserts a new element at the end of the Vec +Create a **function** called `insert` that inserts a new element at the end of the `Vec`. -And another function `at_index` that returns the value found at the index passed as an argument +And another **function** `at_index` that returns the value found at the index passed as an argument. ### Notions -[Common Collections]( https://doc.rust-lang.org/stable/book/ch08-00-common-collections.html) +- [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) ### Expected Functions @@ -16,7 +17,7 @@ And another function `at_index` that returns the value found at the index passed pub fn insert(vec: &mut Vec, val: String) { } -pub fn at_index(vec: &Vec, index: ) -> String { +pub fn at_index(vec: &Vec, index: usize) -> String { } ``` @@ -25,7 +26,7 @@ pub fn at_index(vec: &Vec, index: ) -> String { Here is a possible program to test your function: ```rust -use groceries::{insert, at_index} +use groceries::{insert, at_index}; fn main() { let mut groceries = vec![ diff --git a/subjects/hello_rust/README.md b/subjects/hello_rust/README.md index 0747855c..5201edaa 100644 --- a/subjects/hello_rust/README.md +++ b/subjects/hello_rust/README.md @@ -52,6 +52,11 @@ create and edit the .gitignore file in your repository and add this line: ``` The goal of this setup is to avoid any binary files to be pushed in your gitea accidentaly. +Do not forget to push it to your repository. + +1. `git add .gitignore` +2. `git commit -m "My very first gitignore commit"` +3. `git push` #### 2- get-ready @@ -71,7 +76,7 @@ cargo new --vcs=none --lib name-of-exercise #### 3- try it yourself -Execute the below command inside your repository +Execute the below command for creating a **program** inside your repository ```console cargo new --vcs=none hello_rust diff --git a/subjects/looping/README.md b/subjects/looping/README.md index 0be35338..982b05b6 100644 --- a/subjects/looping/README.md +++ b/subjects/looping/README.md @@ -2,11 +2,11 @@ ### Instructions -Write a program that prints a riddle, receives input from the user and checks that the answer is correct +Write a **program** that prints a riddle, receives input from the user and checks that the answer is correct. -The program must allow indefinite number of trials and only quit after the correct answer is given +The program must allow indefinite number of trials and only quit after the correct answer is given. -Every time the user introduces an incorrect answer the program must print the riddle again and after the user gives the correct answer the program must print the number of tries that took to get the correct answer +Every time the user introduces an incorrect answer the program must print the riddle again and after the user gives the correct answer the program must print the number of tries that took to get the correct answer. Riddle: I am the beginning of the end, and the end of time and space. I am essential to creation, and I surround every place. What am I? diff --git a/subjects/matrix_transposition/README.md b/subjects/matrix_transposition/README.md index a1d479fe..8405c648 100644 --- a/subjects/matrix_transposition/README.md +++ b/subjects/matrix_transposition/README.md @@ -2,9 +2,9 @@ ### Instructions -- Define the structure matrix as a tuple of tuples of `i32`'s +- Define the structure matrix as a tuple of 2 tuples of 2 `i32`'s. -- Define a function that calculate the transpose matrix of a 2x2 matrix. +- Define a **function** that calculates the transpose matrix of a 2x2 matrix. - Note: @@ -17,13 +17,23 @@ Example: ( c d ) ( b d ) ``` -- Matrix must implement Debug, PartialEq and Eq. You can use derive +- Matrix must implement Debug, PartialEq and Eq. You can use derive. -- Remember that you're defining a library so you have to make public the elements that are going to be called from an external crate. +- Remember that you are defining a library so you have to make public the elements that are going to be called from an external crate. ### Notions -[Chapter 7]( https://doc.rust-lang.org/stable/book/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html ) +- [Defining a struct](https://doc.rust-lang.org/stable/book/ch05-01-defining-structs.html) + +- [The Tuple Type](https://doc.rust-lang.org/stable/book/ch03-02-data-types.html?highlight=accessing%20a%20tuple#compound-types) + +- [Tuples](https://doc.rust-lang.org/rust-by-example/primitives/tuples.html) + +- [Tuple Structs without Named Fields](https://doc.rust-lang.org/stable/book/ch05-01-defining-structs.html?highlight=tuple#using-tuple-structs-without-named-fields-to-create-different-types) + +- [Adding Useful Functionality with Derived Traits](https://doc.rust-lang.org/stable/book/ch05-02-example-structs.html?highlight=debug%20deriv#adding-useful-functionality-with-derived-traits) + +- [Chapter 7](https://doc.rust-lang.org/stable/book/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html) ### Expected Function @@ -37,6 +47,9 @@ pub fn transpose(m: Matrix) -> Matrix { Here is a posible program to test your function ```rust +use matrix_transposition::transpose; +use matrix_transposition::Matrix; + fn main() { let matrix = Matrix((1, 3), (4, 5)); println!("Original matrix {:?}", matrix); @@ -44,7 +57,7 @@ fn main() { } ``` -And it's output: +And its output: ```console student@ubuntu:~/[[ROOT]]/test$ cargo run diff --git a/subjects/reverse_string/README.md b/subjects/reverse_string/README.md index 2dbc251a..25b8aed4 100644 --- a/subjects/reverse_string/README.md +++ b/subjects/reverse_string/README.md @@ -2,7 +2,14 @@ ### Instructions -Write a function `rev_str` that takes a `&str` as a parameter, and returns a string with its words reversed. +Write a **function** `rev_str` that takes a `&str` as a parameter, and returns a `String` with its letters reversed. + +### Notions + +- [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) ### Expected Functions @@ -27,7 +34,7 @@ fn main() { } ``` -And it's output: +And its output: ```console student@ubuntu:~/[[ROOT]]/test$ cargo run diff --git a/subjects/scalar/README.md b/subjects/scalar/README.md index c7c20e72..8417bd97 100644 --- a/subjects/scalar/README.md +++ b/subjects/scalar/README.md @@ -1,58 +1,64 @@ -## Scaler +## Scalar ### Instructions -Create the following functions, that receives two parameters: -- sum, that returns the sum between two values from 0 to 255 -- diff, that returns the difference between two values from -32768 to 32767 -- pro, that returns the product of the multiplication between two values from -128 to 127 -- quo, that returns the quotient of the division between two values -- rem, that returns the remainder of the division between two values +Create the following **functions**, which each receives two parameters: +- `sum`, which returns the sum between two values from 0 to 255 +- `diff`, which returns the difference between two values from -32768 to 32767 +- `pro`, which returns the product of the multiplication between two values from -128 to 127 +- `quo`, which returns the quotient of the division between two values (32bit and you have to figure out the second part) +- `rem`, which returns the remainder of the division between two values (32bit and you have to figure out the second part) + +You **must** complete the Expected functions parameters data type accordingly (Replace the Xs)! + ### Notions -- https://doc.rust-lang.org/book/ch03-02-data-types.html +- [Data Types](https://doc.rust-lang.org/book/ch03-02-data-types.html) -### Expected functions +### Expected functions (Incomplete, you must precise the Data Types) ```rust -pub fn sum(a:, b: ) -> { +pub fn sum(a: X , b: X) -> X { } -pub fn diff(a: , b: ) -> { +pub fn diff(a: X, b: X) -> X { } -pub fn pro(a: , b: ) -> { +pub fn pro(a: X, b: X) -> X { } -pub fn quo(a: , b: ) -> { +pub fn quo(a: X, b: X) -> X { } -pub fn rem(a: , b: ) -> { +pub fn rem(a: X, b: X) -> X { } ``` -### Usage: +### Usage : +#### Note that There is no output for this test for you to train to comment accordingly. ```rust +use scalar::*; + fn main() { // sum - println!("sum : {}", sum(234, 2)); + println!("sum : {}", sum(234, 2)); // 'sum : 236' println!("sum : {}", sum(1, 255)); // 'ERROR: attempt to add with overflow' // diff - println!("diff : {}", diff(234, 2)); + println!("diff : {}", diff(234, 2)); // 'diff : 232' println!("diff : {}", diff(-32768, 32766)); // 'ERROR: attempt to subtract with overflow' // product - println!("pro : {}", pro(23, 2)); + 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)); - println!("quo : {}", quo(-128.23, 2.0)); + 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)); - println!("rem : {}", rem(-128.23, 2.0)); + println!("rem : {}", rem(22.0, 2.0));// 'rem : 0' + println!("rem : {}", rem(-128.23, 2.0));// 'rem : -0.22999573' } ``` diff --git a/subjects/speed_transformation/README.md b/subjects/speed_transformation/README.md index 25573ed0..16be31cf 100644 --- a/subjects/speed_transformation/README.md +++ b/subjects/speed_transformation/README.md @@ -2,19 +2,20 @@ ### Instructions -Create a function that receives the speed in km/h (kilometers per hour) and returns the equivalent in m/s (meters per second) +Create a **function** that receives the speed in km/h (kilometers per hour) and returns the equivalent in m/s (meters per second). ### Expected Function ```rust pub fn km_per_hour_to_meters_per_second(km_h: f64) -> f64 { - (10.0 / 36.0) * km_h } ``` ### Usage ```rust +use speed_transformation::km_per_hour_to_meters_per_second; + fn main() { let km_h = 100.0; let m_s = km_per_hour_to_meters_per_second(km_h); diff --git a/subjects/temperature_conv/README.md b/subjects/temperature_conv/README.md index 0c0a8671..223e3fca 100644 --- a/subjects/temperature_conv/README.md +++ b/subjects/temperature_conv/README.md @@ -2,15 +2,17 @@ ### Instructions -Write two functions to transform values of temperatures from celcius to fahrenheit and the other way arraound: +Write two functions which convert values of temperatures from `fahrenheit` to `celcius` and the other way around. -### Expected funcions +To pass this exercise you must use (9/5) in **both** functions. + +### Expected functions ```rust -fn fahrenheit_to_celsius(f: f64) -> f64 { +pub fn fahrenheit_to_celsius(f: f64) -> f64 { } -fn celsius_to_fahrenheit(c: f64) -> f64 { +pub fn celsius_to_fahrenheit(c: f64) -> f64 { } ``` @@ -19,9 +21,18 @@ fn celsius_to_fahrenheit(c: f64) -> f64 { ```rust 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)); } ``` + +And its output: + +```console +student@ubuntu:~/[[ROOT]]/test$ cargo run +-459.67 F = -273.15 C +0 C = 32 F +student@ubuntu:~/[[ROOT]]/test$ +``` + diff --git a/subjects/tuples/README.md b/subjects/tuples/README.md index be01cc7f..7d84a580 100644 --- a/subjects/tuples/README.md +++ b/subjects/tuples/README.md @@ -2,11 +2,25 @@ ### Instructions -- Define a tuple structure to represent a student. +- Define a tuple structure to represent a `Student`. - Each student is identified by an id number of type i32, his/her name and his/her last name as a string Print the content of the tuple to stdout -- Then define three functions to return the id, first name and last name. +- Then define three **functions** to return the id, first name and last name. + +### Notions + +- [Defining a struct](https://doc.rust-lang.org/stable/book/ch05-01-defining-structs.html) + +- [The Tuple Type](https://doc.rust-lang.org/stable/book/ch03-02-data-types.html?highlight=accessing%20a%20tuple#compound-types) + +- [Tuples](https://doc.rust-lang.org/rust-by-example/primitives/tuples.html) + +- [Tuple Structs without Named Fields](https://doc.rust-lang.org/stable/book/ch05-01-defining-structs.html?highlight=tuple#using-tuple-structs-without-named-fields-to-create-different-types) + +- [Adding Useful Functionality with Derived Traits](https://doc.rust-lang.org/stable/book/ch05-02-example-structs.html?highlight=debug%20deriv#adding-useful-functionality-with-derived-traits) + +- [Chapter 7](https://doc.rust-lang.org/stable/book/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html) ### Expected Functions @@ -23,7 +37,7 @@ pub fn last_name(student: &Student) -> String { ### Usage -Here is a program to test you're functions +Here is a program to test your functions ```rust use tuples::*;