diff --git a/docs/piscine-rust-curriculum.md b/docs/piscine-rust-curriculum.md new file mode 100644 index 00000000..f33e92c3 --- /dev/null +++ b/docs/piscine-rust-curriculum.md @@ -0,0 +1,164 @@ +# Piscine Rust curriculum + +--- + +## Week One + +### Quest 01-rust + +Exercices: + +- fibonacci2 | https://github.com/01-edu/public/tree/master/subjects/fibonacci2 +- scalar | https://github.com/01-edu/public/tree/master/subjects/scalar +- temperature-conv | https://github.com/01-edu/public/tree/master/subjects/temperature-conv +- looping | https://github.com/01-edu/public/tree/master/subjects/looping +- speed-transformation | https://github.com/01-edu/public/tree/master/subjects/speed-transformation +- groceries | https://github.com/01-edu/public/tree/master/subjects/groceries +- reverse-string | https://github.com/01-edu/public/tree/master/subjects/reverse-string +- find-factorial | https://github.com/01-edu/public/tree/master/subjects/find-factorial +- matrix-transposition | https://github.com/01-edu/public/tree/master/subjects/matrix-transposition +- division-and-remainder | https://github.com/01-edu/public/tree/master/subjects/division-and-remainder +- tuples | https://github.com/01-edu/public/tree/master/subjects/tuples + + +### Quest 02-rust + +Exercices: + +- ownership | https://github.com/01-edu/public/tree/master/subjects/ownership +- copy | https://github.com/01-edu/public/tree/master/subjects/copy +- borrow | https://github.com/01-edu/public/tree/master/subjects/borrow +- doubtful | https://github.com/01-edu/public/tree/master/subjects/doubtful +- borrow-me-the-reference | https://github.com/01-edu/public/tree/master/subjects/borrow-me-the-reference +- changes | https://github.com/01-edu/public/tree/master/subjects/changes +- string-literals | https://github.com/01-edu/public/tree/master/subjects/string-literals +- name-initials | https://github.com/01-edu/public/tree/master/subjects/name-initials +- arrange-it | https://github.com/01-edu/public/tree/master/subjects/arrange-it +- tic-tac-toe | https://github.com/01-edu/public/tree/master/subjects/tic-tac-toe + + +### Quest 03-rust + +Exercices: + +- circle | https://github.com/01-edu/public/tree/master/subjects/circle +- card-deck | https://github.com/01-edu/public/tree/master/subjects/card-deck +- arrays | https://github.com/01-edu/public/tree/master/subjects/arrays +- strings | https://github.com/01-edu/public/tree/master/subjects/strings +- edit-distance | https://github.com/01-edu/public/tree/master/subjects/edit-distance +- to-url | https://github.com/01-edu/public/tree/master/subjects/to-url +- capitalizing | https://github.com/01-edu/public/tree/master/subjects/capitalizing +- hashing | https://github.com/01-edu/public/tree/master/subjects/hashing +- string-permutation | https://github.com/01-edu/public/tree/master/subjects/string-permutation +- bigger | https://github.com/01-edu/public/tree/master/subjects/bigger +- simple-hash | https://github.com/01-edu/public/tree/master/subjects/simple-hash +- collect | https://github.com/01-edu/public/tree/master/subjects/collect + + +--- + + +## Week Two + + +## Quest 04-rust + +Exercices: + +- unwrap-or-expect | https://github.com/01-edu/public/tree/master/subjects/unwrap-or-expect +- panic | https://github.com/01-edu/public/tree/master/subjects/panic +- handling | https://github.com/01-edu/public/tree/master/subjects/handling +- profanity-filter | https://github.com/01-edu/public/tree/master/subjects/profanity-filter +- question-mark | https://github.com/01-edu/public/tree/master/subjects/question-mark +- banner | https://github.com/01-edu/public/tree/master/subjects/banner +- cipher | https://github.com/01-edu/public/tree/master/subjects/cipher +- error-types | https://github.com/01-edu/public/tree/master/subjects/error-types +- boxing-todo | https://github.com/01-edu/public/tree/master/subjects/boxing-todo + + +## Quest 05-rust + +Exercices: + +- middle-day | https://github.com/01-edu/public/tree/master/subjects/middle-day +- does-it-fit | https://github.com/01-edu/public/tree/master/subjects/does-it-fit +- macro-calculator | https://github.com/01-edu/public/tree/master/subjects/macro-calculator +- shopping-mall | https://github.com/01-edu/public/tree/master/subjects/shopping-mall +- expected-variable | https://github.com/01-edu/public/tree/master/subjects/expected-variable +- mobs | https://github.com/01-edu/public/tree/master/subjects/mobs + + +## Quest 06-rust + +Exercices: + +- traits | https://github.com/01-edu/public/tree/master/subjects/mtraits +- lifetimes | https://github.com/01-edu/public/tree/master/subjects/mlifetimes +- lalgebra-scalar | https://github.com/01-edu/public/tree/master/subjects/mlalgebra-scalar +- matrix | https://github.com/01-edu/public/tree/master/subjects/mmatrix +- matrix-ops | https://github.com/01-edu/public/tree/master/subjects/mmatrix-ops +- matrix-mult | https://github.com/01-edu/public/tree/master/subjects/mmatrix-mult +- lalgebra-vector | https://github.com/01-edu/public/tree/master/subjects/mlalgebra-vector +- blood-types | https://github.com/01-edu/public/tree/master/subjects/mblood-types +- border-cross | https://github.com/01-edu/public/tree/master/subjects/mborder-cross +- roman-numbers | https://github.com/01-edu/public/tree/master/subjects/mroman-numbers +- generics | https://github.com/01-edu/public/tree/master/subjects/mgenerics +- roman-numbers-iter | https://github.com/01-edu/public/tree/master/subjects/mroman-numbers-iter +- vectors-operations | https://github.com/01-edu/public/tree/master/subjects/mvectors-operations +- events | https://github.com/01-edu/public/tree/master/subjects/mevents +- delete-perfix | https://github.com/01-edu/public/tree/master/subjects/mdelete-perfix +- commits-stats | https://github.com/01-edu/public/tree/master/subjects/mcommits-stats + + +--- + +## Week Three + + +## Quest 07-rust + +Exercices: + +- box-it | https://github.com/01-edu/public/tree/master/subjects/box-it +- borrow-box | https://github.com/01-edu/public/tree/master/subjects/borrow-box +- box-recursion | https://github.com/01-edu/public/tree/master/subjects/box-recursion +- how-many-references | https://github.com/01-edu/public/tree/master/subjects/how-many-references +- ref-cell | https://github.com/01-edu/public/tree/master/subjects/ref-cell +- drop-the-thread | https://github.com/01-edu/public/tree/master/subjects/drop-the-thread + + + +## Quest 08-rust + +Exercices: + + +- closures | https://github.com/01-edu/public/tree/master/subjects/closures +- sales | https://github.com/01-edu/public/tree/master/subjects/sales +- adding | https://github.com/01-edu/public/tree/master/subjects/adding +- adding-twice | https://github.com/01-edu/public/tree/master/subjects/adding-twice +- get-products | https://github.com/01-edu/public/tree/master/subjects/get-products +- highest | https://github.com/01-edu/public/tree/master/subjects/highest +- iterators | https://github.com/01-edu/public/tree/master/subjects/iterators +- slices-to-map | https://github.com/01-edu/public/tree/master/subjects/slices-to-map +- step-iterator | https://github.com/01-edu/public/tree/master/subjects/step-iterator +- project-motion | https://github.com/01-edu/public/tree/master/subjects/project-motion + + +## Quest 09-rust + +Exercices: + + +- stars | https://github.com/01-edu/public/tree/master/subjects/stars +- ordinal | https://github.com/01-edu/public/tree/master/subjects/ordinal +- pangram | https://github.com/01-edu/public/tree/master/subjects/pangram +- diamond-creation | https://github.com/01-edu/public/tree/master/subjects/diamond-creation +- scores | https://github.com/01-edu/public/tree/master/subjects/scores +- talking | https://github.com/01-edu/public/tree/master/subjects/talking +- searching | https://github.com/01-edu/public/tree/master/subjects/searching +- logic-number | https://github.com/01-edu/public/tree/master/subjects/logic-number +- rot | https://github.com/01-edu/public/tree/master/subjects/rot +- pig-latin | https://github.com/01-edu/public/tree/master/subjects/pig-latin +- spelling | https://github.com/01-edu/public/tree/master/subjects/spelling +- rgb-match | https://github.com/01-edu/public/tree/master/subjects/rgb-match diff --git a/subjects/arrange_it/README.md b/subjects/arrange_it/README.md index 50a2544c..cf13f373 100644 --- a/subjects/arrange_it/README.md +++ b/subjects/arrange_it/README.md @@ -2,31 +2,33 @@ ### Instructions -Create a function called `arrange_phrase` that takes a string literal as a phrase and returns it organized -Each word will have a number that indicates the position of that word +Create a **function** called `arrange_phrase` that takes a string literal as a phrase and returns it organized +Each word will have a number that indicates the position of that word. -> This exercise will test the **heap allocation** of your function! +> This exercise will test how many times the **heap is going to be allocated**!\ > So try your best to allocate the minimum data on the heap! ### Expected Function ```rust -fn arrange_phrase(phrase: &str) -> String { +pub fn arrange_phrase(phrase: &str) -> String { } ``` ### Notions -- https://doc.rust-lang.org/1.22.0/book/first-edition/the-stack-and-the-heap.html -- https://doc.rust-lang.org/std/primitive.str.html#method.split +- [stack and heap](https://doc.rust-lang.org/1.22.0/book/first-edition/the-stack-and-the-heap.html) +- [str](https://doc.rust-lang.org/std/primitive.str.html) ### Usage Here is a program to test your function ```rust +use arrange_it::*; + fn main() { - println!("{:?}", initials("is2 Thi1s T4est 3a")); + println!("{:?}", arrange_phrase("is2 Thi1s T4est 3a")); } ``` 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/atm-management-system/audit/README.md b/subjects/atm-management-system/audit/README.md index caf2ae7b..57398827 100644 --- a/subjects/atm-management-system/audit/README.md +++ b/subjects/atm-management-system/audit/README.md @@ -34,7 +34,7 @@ ##### Resorting to the user Alice, try to create a new account with: date `"10/10/2012"` account number `"834213"`, country `"UK"`, phone number `"291231392"`, deposit amount $`"1001.20"`, type of account `"saving"`. Then select `"Check accounts"` choose the account you just created. -###### Did the application displayed the account information and the gain of $5.84 of interest on day 10 of every moth? +###### Did the application displayed the account information and the gain of $5.84 of interest on day 10 of every month? ##### Resorting to the user Alice create again an account but with account number "320421" and type of account "fixed01" with the rest of the information as in the last account . Then select `"Check accounts"` and choose the account you just created. @@ -92,4 +92,4 @@ ###### +Did the student add more features to the project? -###### +Did the student optimise the code already given? \ No newline at end of file +###### +Did the student optimise the code already given? 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/borrow/README.md b/subjects/borrow/README.md index 12c24715..0020d6c0 100644 --- a/subjects/borrow/README.md +++ b/subjects/borrow/README.md @@ -2,14 +2,17 @@ ### Instructions -Complete the signature and the body of the `str_len` that receives a string or a string literal and returns its length without taking ownership of the value (i.e, borrowing the value) +Complete the signature and the body of the `str_len` **function** that receives a string or a string literal and returns its length without taking ownership of the value (i.e, borrowing the value). -### Expected Function +### Expected Function (The signature needs to be completed) ```rust pub fn str_len(s: ) -> usize { } ``` +### Notions + +[Primitive Type str](https://doc.rust-lang.org/std/primitive.str.html) ### Usage diff --git a/subjects/borrow_me_the_reference/README.md b/subjects/borrow_me_the_reference/README.md index 64161052..4edd109e 100644 --- a/subjects/borrow_me_the_reference/README.md +++ b/subjects/borrow_me_the_reference/README.md @@ -7,7 +7,11 @@ needing garbage collector. Therefore you must understand ownership in rust. Create the following functions : - - `delete_and_backspace`, imagine that `-` represents the backspace key and the `+` represents the delete key, this function must receive a borrowed string and turn this string into the string without the backspaces and the deletes. + - `delete_and_backspace`, imagine that the `-` represents the `backspace key` and the `+` represents the `delete key`, this function must receive a borrowed string and turn this string into the string that applies the `backspaces` and the `deletes`. + - For example: + - "helll-o" turns into "hello" + + - "he+lllo" turns into "hello" - `is_correct` that borrows a Vector of string literals with some correct and incorrect math equations and replaces the correct equations with `✔` and the wrong with `✘` and returns a `usize` with the percentage of correct equations. 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/changes/README.md b/subjects/changes/README.md index f6f096f2..01c5af92 100644 --- a/subjects/changes/README.md +++ b/subjects/changes/README.md @@ -2,11 +2,16 @@ ### Instructions -Imagine you are working in a software to control smart lights in a house. You have access to an array of all the lights in a house. +Imagine you are working on a software to control smart lights in a house. You have access to an array of all the lights in a house. -Define the associated function `new` to the data structure `Light` which creates a new light with the alias passed in the arguments and a brightness of 0. +Define the associated **function** `new` to the data structure `Light` which creates a new light with the alias passed in the arguments and a brightness of 0. -Define the function `change_brightness` that receives a Vec of lights, an alias and a u8 value and sets the u8 value as the new brightness of the light identified by the alias in the Vec of lights. +Define the **function** `change_brightness` that receives a `Vec` of lights, an `alias` and a `u8`value. The **function** then sets the `u8` value as the new brightness of the light identified by the alias in the Vec of lights. + +### Notions + +[Example of Structs](https://doc.rust-lang.org/book/ch05-02-example-structs.html) +[Keyword Self](https://doc.rust-lang.org/std/keyword.Self.html) ### Expected Functions and Structure @@ -31,6 +36,8 @@ pub fn change_brightness(lights: &mut Vec, alias: &str, value: u8) { Here is an incomplete program to test your function ```rust +use changes::*; + fn main() { // bedroom let mut lights = vec![ 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/copy/README.md b/subjects/copy/README.md index d35ad990..0b6f8c4a 100644 --- a/subjects/copy/README.md +++ b/subjects/copy/README.md @@ -2,17 +2,25 @@ ### Instructions -Your objective is to fix the program so that all functions work. +Your objective is to fix the **functions** work so that the program works. -- `nbr_function`, returns a tuple with the original value, the exponential and logarithm of that value -- `str_function`, returns a tuple with the original value and the exponential of that value as a string -- `vec_function`, returns a tuple with the original value and the logarithm of each value +- `nbr_function` returns a tuple: + - with the `original` value + - the `exponential function` of the value + - and the `natural logarithm` of this `absolute` value +- `str_function` returns a tuple: + - with the `original` value + - and the `exponential function` each value as a string (see the example) +- `vec_function` returns a tuple: + - with the `original` value + - and the `natural logarithm` of each `absolute` value -The objective is to now how ownership works with different types. +The objective is to know how ownership works with different types. ### Notions -- https://doc.rust-lang.org/rust-by-example/scope/move.html +- [scope](https://doc.rust-lang.org/rust-by-example/scope/move.html) +- [Primitive Type f64](https://doc.rust-lang.org/std/primitive.f64.html) ### Expected Functions @@ -32,18 +40,21 @@ pub fn vec_function(b: Vec) -> (Vec, Vec) { Here is a possible program to test your function : ```rust +use copy::*; + fn main() { - let a = String::from("1 2 4 5 6"); - let b = vec![1, 2, 4, 5]; - let c: u32 = 0; - - println!("{:?}", nbr_function(c)); - // output: (12, 162754.79141900392, 2.4849066497880004) - println!("{:?}", vec_function(b)); - // output: ([1, 2, 4], [0.0, 0.6931471805599453, 1.3862943611198906]) - println!("{:?}", str_function(a)); - // output: ("1 2 4", "2.718281828459045 7.38905609893065 54.598150033144236") + let a: u32 = 0; + let b = String::from("1 2 4 5 6"); + let c = vec![1, 2, 4, 5]; + + println!("{:?}", nbr_function(a)); + // output : (0, 1.0, inf) + println!("{:?}", str_function(b)); + // output : ("1 2 4 5 6", "2.718281828459045 7.38905609893065 54.598150033144236 148.4131591025766 403.4287934927351") + println!("{:?}", vec_function(c)); + // output : ([1, 2, 4, 5], [0.0, 0.6931471805599453, 1.3862943611198906, 1.6094379124341003]) } + ``` And its output: @@ -51,7 +62,7 @@ And its output: ```console student@ubuntu:~/[[ROOT]]/test$ cargo run (0, 1.0, inf) -([1, 2, 4, 5], [0.0, 0.6931471805599453, 1.3862943611198906, 1.6094379124341003]) ("1 2 4 5 6", "2.718281828459045 7.38905609893065 54.598150033144236 148.4131591025766 403.4287934927351") +([1, 2, 4, 5], [0.0, 0.6931471805599453, 1.3862943611198906, 1.6094379124341003]) student@ubuntu:~/[[ROOT]]/test$ ``` diff --git a/subjects/doubtful/README.md b/subjects/doubtful/README.md index fcdae000..c8c0bb9f 100644 --- a/subjects/doubtful/README.md +++ b/subjects/doubtful/README.md @@ -2,14 +2,20 @@ ### Instructions -Write a function called `doubtful` that adds to every string passed to it a question mark (?) +Write a function called `doubtful` that adds to every string passed to it a question mark (?). -You have to fix the code to make it compile an for that you can only modify the code where is indicated +You have to complete the signature the functions to make it fit the usage and you also have to modify the usage to be able to do what is expected. + +- Restrictions: + + - `doubtful` cannot return any value. + + - And in the example of the usage you can only modify the argument of the function ### Expected ```rust -pub fn doubtful(s: &mut String) { +pub fn doubtful(s: /*give the correct type*/ ) { } ``` @@ -22,7 +28,9 @@ fn main() { let mut s = String::from("Hello"); println!("Before changing the string: {}", s); - doubtful(&mut s); + + doubtful(/*add your code here*/); + println!("After changing the string: {}", s); } ``` 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/find_factorial/README.md b/subjects/find_factorial/README.md index 183e78fe..c639ab8e 100644 --- a/subjects/find_factorial/README.md +++ b/subjects/find_factorial/README.md @@ -6,7 +6,7 @@ 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. +Example: the factorial of 6 (written 6!) is 1 * 2 * 3 * 4 * 5 * 6 = 720. Do not forget the rules for 0 and 1. diff --git a/subjects/groceries/README.md b/subjects/groceries/README.md index 28c00fa5..f765550e 100644 --- a/subjects/groceries/README.md +++ b/subjects/groceries/README.md @@ -9,7 +9,7 @@ And another **function** `at_index` that returns the value found at the index pa ### 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) +- [Vectors](https://doc.rust-lang.org/stable/book/ch08-01-vectors.html) ### Expected Functions 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/linux/README.md b/subjects/linux/README.md new file mode 100644 index 00000000..fea756ee --- /dev/null +++ b/subjects/linux/README.md @@ -0,0 +1,45 @@ +## Linux + +### Introduction + +Linux is the most widely used kernel (the core of an operating system). + +Linux can be found everywhere there is a computer : data centers, phones, gaming consoles, cars, planes, submarines, space stations... + +Operating systems using the Linux kernel are called "Linux distributions". + +![Tux mascot](tux.png) + +> "But this wasn't to be just any penguin. Above all, Linus wanted one that looked happy, as if it had just polished off a pitcher of beer and then had the best sex of its life." +> +> _Just for Fun: The Story of an Accidental Revolutionary_ (Linus Torvalds, David Diamond) + +--- + +This series of projects will introduce you to a Linux distribution called Debian and its use in servers (always-on computers providing the required services for Internet and applications). + +You'll become a better programmer by knowing what's underneath your programs and what's behind Cloud services. + +It will also allow you to learn some tricks to better control your machine and servers. + +### Virtualization + +To practice in a standardized way and without the risk of altering your own operating system, install the hypervisor [VirtualBox](https://www.virtualbox.org/wiki/Downloads). + +This will allow you to run virtual machines (virtual computers accessible through a window). + +This way, whatever your operating system, you can, for example, run Linux, Windows & macOS in 3 separate windows at the same time. + +### Installation + +Operating systems are usually installed with a "disk image" that can be written to a USB stick or CD/DVD for installation on a computer, or kept as is for installation in a virtual machine (which is the case here). + +Install Debian (ISO installer "netinst" is recommended) in a VM (Virtual Machine). The steps are : + +- Create the VM. +- Start the VM and attach the ISO file as an optical drive (CD/DVD). +- Follow the steps of the installer, it will reboot with a Debian system ready to use. + +### Shut down + +Gracefully close the VM using "ACPI Shutdown". It's like pressing the power button of a real computer. diff --git a/subjects/linux/audit/README.md b/subjects/linux/audit/README.md new file mode 100644 index 00000000..511fe00e --- /dev/null +++ b/subjects/linux/audit/README.md @@ -0,0 +1,7 @@ +#### Functional + +###### Is VirtualBox correctly installed ? + +###### Does the virtual machine boot Debian properly (in less than 2 minutes) ? + +###### After the boot is complete, does the system react to the ACPI Shutdown and does the virtual machine stop ? diff --git a/subjects/linux/tux.png b/subjects/linux/tux.png new file mode 100644 index 00000000..30b73cee Binary files /dev/null and b/subjects/linux/tux.png differ diff --git a/subjects/looping/README.md b/subjects/looping/README.md index 982b05b6..93d71c33 100644 --- a/subjects/looping/README.md +++ b/subjects/looping/README.md @@ -12,6 +12,11 @@ Riddle: I am the beginning of the end, and the end of time and space. I am essen Answer: The letter e +### Notions + +- [Moduler std::io](https://doc.rust-lang.org/std/io/index.html) +- [loop](https://doc.rust-lang.org/std/keyword.loop.html) + ### Usage ```console diff --git a/subjects/matrix_transposition/README.md b/subjects/matrix_transposition/README.md index 8405c648..bb214c3d 100644 --- a/subjects/matrix_transposition/README.md +++ b/subjects/matrix_transposition/README.md @@ -13,7 +13,7 @@ Example: ``` -( a b ) __ transposition __> ( a d ) +( a b ) __ transposition __> ( a c ) ( c d ) ( b d ) ``` diff --git a/subjects/name_initials/README.md b/subjects/name_initials/README.md index e52fb636..df573efe 100644 --- a/subjects/name_initials/README.md +++ b/subjects/name_initials/README.md @@ -2,26 +2,26 @@ ### Instructions -Create a function called `initials`, this function will receive a vector of string literals +Create a **function** called `initials`, this function will receive a vector of string literals with names and return a vector of Strings with the initials of each name. -> This exercise will test the **heap allocation** of your function! +> This exercise will test how many times the **heap is going to be allocated**!\ > So try your best to allocate the minimum data on the heap! ### Notions -- https://doc.rust-lang.org/1.22.0/book/first-edition/the-stack-and-the-heap.html +- [stack and heap](https://doc.rust-lang.org/1.22.0/book/first-edition/the-stack-and-the-heap.html) ### Expected Function ```rust -fn initials(names: &mut Vec<&str>) -> Vec { +pub fn initials(names: Vec<&str>) -> Vec { } ``` ### Usage -Here is a program to test your function +Here is a program to test your function: ```rust use name_initials::initials; diff --git a/subjects/ownership/README.md b/subjects/ownership/README.md index 6a5eda1f..ec14faf9 100644 --- a/subjects/ownership/README.md +++ b/subjects/ownership/README.md @@ -2,10 +2,14 @@ ### Instruction -- Create a function that takes ownership of a string and returns the first sub-word in it +- Create a **function** that takes ownership of a string and returns the first sub-word in it - It should work for `camelCase` as well as `snake_case` +### Notions + +- [ownership](https://doc.rust-lang.org/book/ch04-00-understanding-ownership.html) + ### Expected Function ```rust @@ -15,9 +19,11 @@ pub fn first_subword(mut s: String) -> String { ### Usage -Here is a program to test your function +Here is a program to test your function: ```rust +use ownership::first_subword; + fn main() { let s1 = String::from("helloWorld"); let s2 = String::from("snake_case"); @@ -31,7 +37,7 @@ fn main() { } ``` -And its output +And its output: ```console student@ubuntu:~/[[ROOT]]/test$ cargo run diff --git a/subjects/rt/README.md b/subjects/rt/README.md new file mode 100644 index 00000000..b5ee2c4d --- /dev/null +++ b/subjects/rt/README.md @@ -0,0 +1,101 @@ +## rt + +There are two ways to render a 3d scene into a 2d image: `rasterization` which basically converts the shapes and geometric figures to pixels and applies calculations to obtain the color, the shadows, the refraction, etc... of those pixels. The other method is called `ray tracing` and consist in drawing each pixel with its color, shadows, refraction, reflection, etc.... already present from the start. + +Imagine a camera pointing at a scene, and from that camera, a bunch of rays are coming, which bounce from object to object until they reach the light source (lamp, sun, etc...). This is basically how a ray tracer works. + +In `ray tracing` each of these rays can be seen as a pixel in the image captured by the camera. Recursively the ray tracer will calculate where the light comes from in that pixel, allowing to give that pixel a color with some shadow aspect, some refraction aspect, and so on. + +To understand better how ray tracing works, it is highly suggested that you search online this subject, as it can get quite complicated. + +Below is an example of an image which your ray tracer should be able to produce: + +![image.png](raytrace.png) + +### Objectives + +In this project, you have to implement the ray tracer method in order to be able to render a computer generated image containing a few objects. + +When building your ray tracer you have to take some points into consideration: + +- you need to be able to create at least 4 simple objects: a sphere, a cube, a flat plane and a cylinder. +- your program must be able to change an object location before creating the image. (Example: render a sphere with its center on the point (1,1,1)). +- you have to be able to look at the same scene from different angles by moving the camera/point of view. +- you also have to implement simple light management, which includes: different brightness and shadows. + +As your ray tracer will probably be a bit slow to render high resolution scenes, you should make 4 .ppm images for the auditors to evaluate. The scenarios of these 4 images that you have to create consist of: + +- a scene with a sphere; +- a scene with a flat plane and a cube with lower brightness than in the sphere image; +- a scene with one of each of all the objects (one cube, one sphere, one cylinder and one flat plane); +- a scene like the previous one, but with the camera in another position (thus generating the same image from a different perspective). + +All of the images should be in the format of 800x600. However, while testing you should use smaller resolution images in order to reduce your rendering time (a 1200x1000 can take up to 40 mins to create). + +Another aspect you should consider is that the auditor will have to use your ray tracer, so make it as usable and optimized as possible. You should provide the auditor clear documentation. + +#### Documentation + +By documentation we mean, the explaining of how does the ray tracer work and how to work with it, for example: how to create an object, how to change brightness in a scene, etc... A new user of your ray tracer, after reading the documentation has to be able to use it without much guessing work. + +You will have to create a [markdown](https://www.markdownguide.org/getting-started/) file, which will have to contain: + +- Explanation on the features of your ray tracer +- Code examples and explanations on how to: + - create an instance of each object (a sphere, a cube, a flat plane and a cylinder) + - change the brightness + - change the camera position and angle + +### Instructions + +In order to render images you will create a [.ppm](https://www.cs.swarthmore.edu/~soni/cs35/f13/Labs/extras/01/ppm_info.html) file. A .ppm file consists of an image header and an image body. Example: + +``` +P3 \ +4 4 > Image Header +255 / +0 0 0 \ +0 0 0 \ +0 0 0 | +255 0 255 | +100 0 0 | +0 255 175 | +0 0 0 | +0 0 0 > Image Body +0 0 0 | +0 0 0 | +015 175 | +0 0 0 | +255 0 255 | +0 0 0 | +0 0 0 / +255 255 255 / +``` + +The image header consists of three lines: + +- the first one is the image format: what type of PPM (full color, ASCII enconding) image it is. P3 stands for the Portable PixMap type so you will be using this one. +- the next stands for how many columns and rows of pixels the image will contain. +- and the third line is the maximum color value, 255 is the most common value since the rgb color code is very well known. + +All the other lines below, are the rgb values for each pixel, for example the first line of the image body represents a black pixel (rgb(0,0,0) -> black). Each line represents one pixel, starting on the top left corner transitioning to the right and, in this case, the fifth line is the pixel in the first row on the second column. + +So with this in mind, you will have to make an algorithm that fills a file by printing each line. You can use the cargo command this way: `cargo run > output.ppm`. This will print the standard output to the file `output.ppm`. + +In order to create the previous mentioned objects you will need to search online for documentation about the geometrics of each. + +### Bonus + +As bonus for this project you can implement: + +- Textures to the surfaces of the objects +- Reflection and refraction effects on the objects (make them shiny or reflective) +- Add particles +- Add fluids + +This project will help you learn about: + +- [Ray Tracing]() +- Computer generated imagery (CGI) +- Algorithms +- Geometry and maths diff --git a/subjects/rt/audit/README.md b/subjects/rt/audit/README.md new file mode 100644 index 00000000..7c99d5b7 --- /dev/null +++ b/subjects/rt/audit/README.md @@ -0,0 +1,33 @@ +#### Functional + +##### Using the ray tracer construct any scene you want, including at least one of all objects. (this can take a while to render, so in the meantime you can skip the first two questions and answer the following ones) + +###### Does the image correspond to the scene you created? + +##### Move the camera and render the same scene. + +###### Does the image correspond to the same scene, but from a different perspective? + +###### Did the student provide 4 .ppm pictures? + +###### Does one of these images consist of a scene with a sphere? + +###### Does one of these images consist of a scene with a flat plane and a cube with lower brightness than in the sphere image? + +###### Does one of these images consist of a scene with one of each of all the objects (one cube, one sphere, one cylinder and one flat plane)? + +###### Does one of these images consist of a scene like the previous one, but with the camera in another position (thus generating the same image from a different perspective)? + +###### Considering all of the previous pictures, can you see shadows from the objects? + +###### Did the student provide clear documentation for the ray tracer on how to use it (create elements, change brightness and move the camera)? + +#### Bonus + +###### +Is it possible to add textures to the surface of the objects? + +###### +Is it possible to make reflective and/or refractive objects? + +###### +Is it possible to add particles? + +###### +Is it possible to add fluids? diff --git a/subjects/rt/raytrace.png b/subjects/rt/raytrace.png new file mode 100644 index 00000000..891bdfe5 Binary files /dev/null and b/subjects/rt/raytrace.png differ 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_literal/README.md b/subjects/string_literals/README.md similarity index 71% rename from subjects/string_literal/README.md rename to subjects/string_literals/README.md index ddbf41f7..9215285d 100644 --- a/subjects/string_literal/README.md +++ b/subjects/string_literals/README.md @@ -10,8 +10,8 @@ Create the following functions: - `split_at`, that divides a string in two returning a tuple - `find', that returns the index if the first character of a given string that matches the pattern -> This exercise will test the **heap allocation** of your function! -> So try your best to allocate the minimum data on the heap! (hit: &str) +> This exercise will test how many times the **heap is going to be allocated**!\ +> So try your best to allocate the minimum data on the heap! ### Notions @@ -42,12 +42,25 @@ fn find(v: &str, pat: char) -> usize { Here is a program to test your function ```rust - +use string_literal::*; + +fn main() { + println!("{}", is_empty("")); + println!("{}", is_ascii("rust")); + println!("{}", contains("rust", "ru")); + println!("{:?}", split_at("rust", 2)); + println!("{}", find("rust", 'u')); +} ``` And its output ```console student@ubuntu:~/[[ROOT]]/test$ cargo run +true +true +true +("ru", "st") +1 student@ubuntu:~/[[ROOT]]/test$ ``` 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/tic_tac_toe/README.md b/subjects/tic_tac_toe/README.md index 5086b6f9..97d5728c 100644 --- a/subjects/tic_tac_toe/README.md +++ b/subjects/tic_tac_toe/README.md @@ -2,32 +2,40 @@ ### Instructions -You must create a tic tac toe checker. +You must create a `tic tac toe` checker. Create the following functions: -- `tic_tac_toe` that receives a table of vectors (Vec>) and returns a string : `player O won` or `player X won` or `Tie` -- `diagonals` that will receive a player and a table. It should return a boolean, this must return true if all the diagonals are completed by the player -- `horizontal` that will receive a player and a table. It should return a boolean, this must return true if one of the horizontal lines are completed by the player -- `vertical` that will receive a player and a table. It should return a boolean, this must return true if one of the vertical lines are completed by the player +- `tic_tac_toe` which receives: + - a table of vectors (Vec>). + - It should return a String `player O won` or `player X won` or `Tie`. +- `diagonals` which will receive: + - a player and a table. + - It should return a boolean, this must return `true` if all the diagonals are completed by the player. +- `horizontal` which will receive: + - a player and a table. + - It should return a boolean, this must return `true` if one of the horizontal lines are completed by the player. +- `vertical` which will receive: + - a player and a table. + - It should return a boolean, this must return `true` if one of the vertical lines are completed by the player. ### Notions -- https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html +- [references and borrowing](https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html) ### Expected Functions ```rust -fn tic_tac_toe(table: Vec>) -> String { +pub fn tic_tac_toe(table: Vec>) -> String { } -fn diagonals(player: &str, table: &Vec>) -> bool { +pub fn diagonals(player: &str, table: &Vec>) -> bool { } -fn horizontal(player: &str, table: &Vec>) -> bool { +pub fn horizontal(player: &str, table: &Vec>) -> bool { } -fn vertical(player: &str, table: &Vec>) -> bool { +pub fn vertical(player: &str, table: &Vec>) -> bool { } ``` @@ -36,6 +44,8 @@ fn vertical(player: &str, table: &Vec>) -> bool { Here is a program to test your function ```rust +use tic_tac_toe::*; + fn main() { println!( "{:?}", 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));