diff --git a/subjects/arrays/README.md b/subjects/arrays/README.md index a5208f77..047e9a09 100644 --- a/subjects/arrays/README.md +++ b/subjects/arrays/README.md @@ -2,20 +2,27 @@ ### Instructions -Define a function call thirtytwo_tens that returns an array with 32 positions fill with only the value 10: [10, 10, 10, ... 10].len() -= 32 +Define a **function** called `thirtytwo_tens` that returns an array with 32 positions filled with only the value `10`: -Write a function that takes an array of i32 and returns the sum of the elements (make it work with the main) +- [10, 10, 10, ... 10].len() + = 32 + +Write a **function** that takes an array of i32 and returns the sum of the elements (make it work with the main). + +### Notions + +[arrays](https://doc.rust-lang.org/std/primitive.array.html) ### Expected functions -The type of one of the arguments is missing use the example `main` function to determine the correct type. +The type of one of the arguments is missing. Use the example `main` function to determine the correct type. ```rust -fn sum(a: _) -> i32 { +pub fn sum(a: _) -> i32 { + //type of argument missing in the signature here } -fn thirtytwo_tens() -> [i32; 32] { +pub fn thirtytwo_tens() -> [i32; 32] { } ``` @@ -23,19 +30,19 @@ fn thirtytwo_tens() -> [i32; 32] { Here is a program to test your function. -There is things missing in this program use the output and the other information that you have available to determine what is missing. +There are things missing in this program. Use the output and the other information that you have available to retrieve what is missing. ```rust use arrays::{sum, thirtytwo_tens}; fn main() { let a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - let a1: Vec = (1..11).; - let b = [_; 10]; + let a1: Vec = (1..11).; //missing info here + let b = [_; 10]; //missing info here - println!("The Sum of the elements in {:?} = {}", a, sum(a)); - println!("The Sum of the elements in {:?} = ", a1, sum(a1)); - println!("The Sum of the elements in {:?} = {}", b, sum(b)); + println!("The Sum of the elements in {:?} = {}", a, sum(a));//missing info here + println!("The Sum of the elements in {:?} = ", a1, sum(a1));//missing info here + println!("The Sum of the elements in {:?} = {}", b, sum(b));//missing info here println!( "Array size {} with only 10's in it {:?}", thirtytwo_tens().len(), @@ -44,7 +51,7 @@ fn main() { } ``` -And its output +And its output: ```console student@ubuntu:~/[[ROOT]]/test$ cargo run diff --git a/subjects/bigger/README.md b/subjects/bigger/README.md index fbd38a80..9687e5b0 100644 --- a/subjects/bigger/README.md +++ b/subjects/bigger/README.md @@ -4,6 +4,10 @@ Create the function `bigger` that gets the biggest positive number in the `HashMap`. +### Notions + +[hash maps](https://doc.rust-lang.org/book/ch08-03-hash-maps.html) + ### Expected Function ```rust @@ -16,9 +20,11 @@ pub fn bigger(h: HashMap<&str, i32>) -> i32 { Here is a program to test your function. ```rust +use std::collections::HashMap; use bigger::bigger; + fn main() { - + let mut hash = HashMap::new(); hash.insert("Daniel", 122); hash.insert("Ashley", 333); diff --git a/subjects/capitalizing/README.md b/subjects/capitalizing/README.md index 34ad3196..ec0afadd 100644 --- a/subjects/capitalizing/README.md +++ b/subjects/capitalizing/README.md @@ -2,11 +2,11 @@ ### Instructions -Complete the `capitalize_first` function that turns the first letter of a string uppercase. +Complete the `capitalize_first` **function** which turns the first letter of a string to uppercase. -Complete the `title_case` function that turns the first letter of each word in a string uppercase. +Complete the `title_case` **function** which turns the first letter of each word in a string to uppercase. -Complete the `change_case` function that turns the uppercase letters of a string into lowercase and the lowercase letters into uppercase. +Complete the `change_case` **function** which turns the uppercase letters of a string into lowercase and the lowercase letters into uppercase. ### Expected Functions @@ -23,10 +23,10 @@ pub fn change_case(input: &str) -> String { ### Usage -Here is a program to test your function. +Here is a program to test your functions. ```rust -use capitalizing::capitalizing; +use capitalizing::*capitalizing*; fn main() { println!("{}", capitalize_first("joe is missing")); @@ -37,7 +37,7 @@ fn main() { And its output -```console +```consoole student@ubuntu:~/[[ROOT]]/test$ cargo run Joe is missing Jill Is Leaving A diff --git a/subjects/card_deck/README.md b/subjects/card_deck/README.md index 3d3a6c27..31fe440e 100644 --- a/subjects/card_deck/README.md +++ b/subjects/card_deck/README.md @@ -2,52 +2,54 @@ ### Instructions -Represent cards from a desk - -- A standard deck of cards has 52 cards: 4 suits and 13 cards per suit - -- Start by creating the `Suit` enum and implement the associated -function `random` which returns a random `Suit` (`Heart`, -`Diamond`, `Spade` or `Club`) +A standard deck of cards has 52 cards: 4 suits and 13 cards per suit. +Represent the cards from a deck: +- Start by creating the `Suit` enum +- implement the associated **function** `random` which returns a random `Suit` (`Heart`, `Diamond`, `Spade` or `Club`) - Then create the `Rank` enum that can have the value -`Ace`, `King`, `Queen`, `Jack`, and `Number` associated to an `u8` -value to represent the ranks 2 through 10 -After create an associated function to `Rank` called `Random` that -returns a random `Rank` - + `Ace`, `King`, `Queen`, `Jack`, and `Number` associated to an `u8` + value to represent the ranks 2 through 10 +- After create an associated **function** to `Rank` called `Random` that + returns a random `Rank` - Finally create a structure name `Card` which has the fields `suit` -and `rank` + and `rank` Define: -The associated function `translate` for Rank and Suite -- for `Suit`, `tranlate` makes the translation between an integer value (u8) and the suit of a card (1 -> Heart, 2 -> Diamonds, 3 -> Spade, 4 -> Club) -- for `Rank`, `translate` makes the tranlation between an integer value (u8) and the rank ( 1 -> Ace, 2 -> 2, .., 10 -> 10, 11 -> Jack, 12 -> Queen, 13 -> King) +- The associated **function** `translate` for `Rank` and `Suit`: + - For `Suit`, `translate` makes the translation between an integer value (u8) and the suit of a card (1 -> Heart, 2 -> Diamonds, 3 -> Spade, 4 -> Club) + - For `Rank`, `translate` makes the translation between an integer value (u8) and the rank ( 1 -> Ace, 2 -> 2, .., 10 -> 10, 11 -> Jack, 12 -> Queen, 13 -> King) +- The associated **function** `random` for `Rank` and `Suit` which returns a random `Rank` and `Suit` respectively +- Finally define the **function** `winner_card` which returns `true` if the card passed as an argument is an Ace of spades -The associated function `random` for `Rank` and `Suit` which returns a random rand and suit respectively +### Notions -Finally define the function `winner_card` that returns true if the card passed as an argument is an Ace of spades +[Crate rand](https://docs.rs/rand/0.5.0/rand/) ### Expected Functions and Structures ```rust -pub fn random() -> Suit { +pub enum Suit { } -pub fn translate(value: u8) -> Suit { +pub enum Rank { } -pub fn random() -> Rank { -} +impl Suit { + pub fn random() -> Suit { + } -pub fn traslate(value: u8) -> Rank { + pub fn translate(value: u8) -> Suit { + } } -pub enum Suit { -} +impl Rank { + pub fn random() -> Rank { + } -pub enum Rank { + pub fn translate(value: u8) -> Rank { + } } pub struct Card { @@ -67,7 +69,7 @@ fn main() { suit: Suit::random(), }; - println!("You're card is {:?}", your_card); + println!("Your card is {:?}", your_card); // Now if the card is an Ace of Spades print "You are the winner" if card_deck::winner_card(your_card) { @@ -80,6 +82,6 @@ And its output ```console student@ubuntu:~/[[ROOT]]/test$ cargo run -You're card is Card { suit: Club, rank: Ace } +Your card is Card { suit: Club, rank: Ace } student@ubuntu:~/[[ROOT]]/test$ ``` diff --git a/subjects/circle/README.md b/subjects/circle/README.md index df8247e1..e8efb61a 100644 --- a/subjects/circle/README.md +++ b/subjects/circle/README.md @@ -2,25 +2,30 @@ ### Instructions -Create the structures `Circle` and `Point` and the methods necessary for the code in [usage](#usage) to compile and run giving the expected result. - -Methods: - - Point; - distance() - - Circle: - diameter -> returns the diameter of the circle - area -> returns the area of the circle - intersection -> returns true if the 2 circles intersect -Associated Functions - - Circle: - new -> receives three 64 bits floating point numbers in the following - order: x, y and radius (x and y are the coordinates of the center). - and returns a new circle - - +Create the structures `Circle` and `Point` (which will be made of two coordinates) and the methods necessary for the code in [usage](#usage) to compile and run giving the expected output. + +#### Methods: + +- Point: + distance() -> returns the distance between two coordinates. +- Circle: + - diameter() -> returns the diameter of the circle. + - area() -> returns the area of the circle. + - intersect() -> which returns true, if 2 circles intersect. + +#### Associated Functions + +- Circle: + - new() -> receives three 64 bits floating point numbers in the following order: x, y and radius (x and y are the coordinates of the center of the new circle). The function returns a new circle + +### Notions + +- [Using Structs](https://doc.rust-lang.org/book/ch05-00-structs.html) +- [f64 constants](https://doc.rust-lang.org/std/f64/consts/index.html) + ### Expected Functions and Structures -This snippets are incomplete and it's part of the exercise to discover the how to complete them +This snippets are incomplete and it is part of the exercise to discover how to complete them. In the [usage](#usage) you will find all the information that you need. ```rust struct Circle { @@ -29,7 +34,7 @@ struct Circle { } struct Point { -// ... +// ... } // Point @@ -46,6 +51,9 @@ fn diameter(_) -> _ { fn area() -> _ { } + +fn intersect(self, other: ) -> bool { +} ``` ### Usage diff --git a/subjects/collect/README.md b/subjects/collect/README.md index 89c372d9..443d37cb 100644 --- a/subjects/collect/README.md +++ b/subjects/collect/README.md @@ -2,12 +2,12 @@ ### Instructions -Implement the function bubble_sort which receives a vector Vec and return the same vector but in increasing order using the bubble sort algorithm +Implement the **function** `bubble_sort` which receives a vector Vec and returns the same vector but in increasing order using the bubble sort algorithm. ### Expected Function ```rust -fn bubble_sort(vec: &mut Vec) { +pub fn bubble_sort(vec: &mut Vec) { } ``` @@ -16,6 +16,8 @@ fn bubble_sort(vec: &mut Vec) { Here is a program to test your function. ```rust +use collect::*; + fn main() { let ref mut v = vec![3, 2, 4, 5, 1, 7]; let mut b = v.clone(); @@ -27,7 +29,7 @@ fn main() { } ``` -And its output +And its output: ```console student@ubuntu:~/[[ROOT]]/test$ cargo run diff --git a/subjects/edit_distance/README.md b/subjects/edit_distance/README.md index 91195bb6..78321e76 100644 --- a/subjects/edit_distance/README.md +++ b/subjects/edit_distance/README.md @@ -2,7 +2,7 @@ ### Instructions -Create a function call `edit_distance` that calculates the minimum number of changes (insertion, deletions and substitutions) that need to be made to a string `source` to arrive to another `target` string +Create a **function** called `edit_distance` which calculates the minimum number of changes (insertions, deletions and/or substitutions) which need to be made to a string `source` to transform to another string `target`. ### Expected Function @@ -13,13 +13,15 @@ pub fn edit_distance(source: &str, target: &str) -> usize { ### Notions -For more information and examples https://en.wikipedia.org/wiki/Edit_distance +For more information and examples go to this [link](https://en.wikipedia.org/wiki/Edit_distance) ### Usage Here is a program to test your function. ```rust +use edit_distance::*; + fn main() { let source = "alignment"; let target = "assignment"; @@ -32,7 +34,7 @@ fn main() { } ``` -And its output +And its output: ```console student@ubuntu:~/[[ROOT]]/test$ cargo run diff --git a/subjects/hashing/README.md b/subjects/hashing/README.md index a82d9732..7bcb3106 100644 --- a/subjects/hashing/README.md +++ b/subjects/hashing/README.md @@ -2,25 +2,29 @@ ### Instructions -Given a list of integers (Vec) write three functions +Given a list of integers (Vec) write three **functions**. -Write a function called `mean` that calculates the `mean` (the average value) of all the values in the list +Write a **function** called `mean` that calculates the `mean` (the average value) of all the values in the list. -Write a function called `median` that calculates the `median` (for a sorted list is the value in the middle) +Write a **function** called `median` that calculates the `median` (for a sorted list, it is the value in the middle). -Write a function called `mode` that calculates the mode (the value -that appears more often) +Write a **function** called `mode` that calculates the mode (the value +that appears more often). + +### Notions + +[hash maps](https://doc.rust-lang.org/book/ch08-03-hash-maps.html) ### Expected Functions ```rust -fn mean(list: &Vec) -> f64 { +pub fn mean(list: &Vec) -> f64 { } -fn median(list: &Vec) -> i32 { +pub fn median(list: &Vec) -> i32 { } -fn mode(list: &Vec) -> i32 { +pub fn mode(list: &Vec) -> i32 { } ``` @@ -29,7 +33,7 @@ fn mode(list: &Vec) -> i32 { Here is a program to test your function. ```rust -use hashing; +use hashing::*; fn main() { println!("Hello, world!"); @@ -40,7 +44,7 @@ fn main() { } ``` -And its output +And its output; ```console student@ubuntu:~/[[ROOT]]/test$ cargo run diff --git a/subjects/simple_hash/README.md b/subjects/simple_hash/README.md index a90c4c1f..a6d5d416 100644 --- a/subjects/simple_hash/README.md +++ b/subjects/simple_hash/README.md @@ -2,10 +2,11 @@ ### Instructions -Create the function `contain` that checks a `HashMap` to see if it contains the given key. +Create a **function** `contain` that checks a `HashMap` to see if it contains a given key. -Create the function `remove` that removes a given key from the `HashMap`. +Create a **function** `remove` that removes a given key from the `HashMap`. +- Note: pay attention to the comment in the [usage](#usage) ### Notions - https://doc.rust-lang.org/rust-by-example/std/hash.html @@ -23,7 +24,7 @@ pub fn remove(h: &mut HashMap<&str, i32>, s: &str) {} Here is a program to test your function. ```rust -use simple_hash::simple_hash; +use simple_hash::*; use std::collections::HashMap; fn main() { @@ -35,18 +36,24 @@ fn main() { println!( "Does the HashMap contains the name Roman? => {}", - contain(&hash, "Roman") + contain(hash.clone(), "Roman") + //----------^^^^^^^^ + // this is not correct, fix it to match the solution the expected function ); println!( "Does the HashMap contains the name Katie? => {}", - contain(&hash, "Katie") + contain(hash.clone(), "Katie") + //----------^^^^^^^^ + // this is not correct, fix it to match the solution the expected function ); - println!("Removing Robert {:?}", remove(&mut hash, "Robert")); + println!("Removing Robert {:?}", remove(hash.clone(), "Robert")); println!( "Does the HashMap contains the name Robert? => {}", - contain(&hash, "Robert") + contain(hash.clone(), "Robert") + //----------^^^^^^^^ + // this is not correct, fix it to match the solution the expected function ); - println!("Hash {:?}", hash); + println!("Hash {:?}", &hash); } ``` diff --git a/subjects/string_permutation/README.md b/subjects/string_permutation/README.md index d33f0222..0fda4ea5 100644 --- a/subjects/string_permutation/README.md +++ b/subjects/string_permutation/README.md @@ -2,12 +2,19 @@ ### Instructions -Define the function `is_permutation` that returns true if the string `s1` is a permutation of `s2`, otherwise it returns false `s1` is a permutation of `s2` if all the elements in `s1` appear the same number of times in `s2` and all the characters in `s1` appear in `s2` even if in different order) +Define the **function** `is_permutation` that returns true if: + +- the string `s1` is a permutation of `s2`, otherwise it returns false. +- `s1` is a permutation of `s2` if all the elements in `s1` appear the same number of times in `s2` and all the characters in `s1` appear in `s2` even if they are in different order. + +### Notions + +[hash maps](https://doc.rust-lang.org/book/ch08-03-hash-maps.html) ### Expected Function ```rust -fn is_permutation(s1: &str, s2: &str) -> bool { +pub fn is_permutation(s1: &str, s2: &str) -> bool { } ``` @@ -16,6 +23,8 @@ fn is_permutation(s1: &str, s2: &str) -> bool { Here is a program to test your function. ```rust +use string_permutation::*; + fn main() { let word = "thought"; let word1 = "thougth"; diff --git a/subjects/strings/README.md b/subjects/strings/README.md index 8c68e9fa..7a51cf40 100644 --- a/subjects/strings/README.md +++ b/subjects/strings/README.md @@ -2,12 +2,12 @@ ### Instructions -Write a function that receives a string slice and returns the number of character of the string +Write a **function** which receives a string slice and returns the number of characters of the string. ### Expected Function ```rust -fn char_length(s: &str) -> usize { +pub fn char_length(s: &str) -> usize { } ``` @@ -16,6 +16,8 @@ fn char_length(s: &str) -> usize { Here is a program to test your function. ```rust +use strings::*; + fn main() { println!("length of {} = {}", "❤", char_length("❤")); println!("length of {} = {}", "形声字", char_length("形聲字")); diff --git a/subjects/to_url/README.md b/subjects/to_url/README.md index f328153d..828cae37 100644 --- a/subjects/to_url/README.md +++ b/subjects/to_url/README.md @@ -2,7 +2,7 @@ ### Instructions -Define a function called `to_url` that takes a string and substitutes every white-space with '%20' +Define a **function** called `to_url` that takes a string and substitutes every white-space with '%20'. ### Expected Function @@ -16,6 +16,8 @@ pub fn to_url(s: &str) -> String { Here is a program to test your function. ```rust +use to_url::*; + fn main() { let s = "Hello, world!"; println!("{} to be use as an url is {}", s, to_url(s));