diff --git a/subjects/arrange_it/README.md b/subjects/arrange_it/README.md index 50a2544c..6d962c25 100644 --- a/subjects/arrange_it/README.md +++ b/subjects/arrange_it/README.md @@ -2,8 +2,8 @@ ### 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! > So try your best to allocate the minimum data on the heap! @@ -11,22 +11,26 @@ Each word will have a number that indicates the position of that word ### 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.split](https://doc.rust-lang.org/std/primitive.str.html#method.split) +- [str.matches](https://doc.rust-lang.org/std/primitive.str.html#method.matches) +- [str.replace](https://doc.rust-lang.org/std/primitive.str.html#method.replace) ### 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/string_literal/README.md b/subjects/string_literal/README.md index ddbf41f7..9c0bac96 100644 --- a/subjects/string_literal/README.md +++ b/subjects/string_literal/README.md @@ -2,13 +2,13 @@ ### Instructions -Create the following functions: +Create the following **functions**: -- `is_empty`, that returns true if a string is empty -- `is_ascii`, that returns true if all characters of a given string is in ASCII range -- `contains`, that returns true if the string contains a pattern given -- `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 +- `is_empty`, which returns `true` if a string is empty +- `is_ascii`, which returns `true` if all characters of a given string is in ASCII range +- `contains`, which returns `true` if the string contains a given pattern +- `split_at`, which divides a string in two returning a tuple +- `find`, which returns the index if the first character of a given string which 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) diff --git a/subjects/string_literals/README.md b/subjects/string_literals/README.md new file mode 100644 index 00000000..ddbf41f7 --- /dev/null +++ b/subjects/string_literals/README.md @@ -0,0 +1,53 @@ +## string literal + +### Instructions + +Create the following functions: + +- `is_empty`, that returns true if a string is empty +- `is_ascii`, that returns true if all characters of a given string is in ASCII range +- `contains`, that returns true if the string contains a pattern given +- `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) + +### Notions + +- https://doc.rust-lang.org/1.22.0/book/first-edition/the-stack-and-the-heap.html +- https://doc.rust-lang.org/rust-by-example/primitives/literals.html + +### Expected Functions + +```rust +fn is_empty(v: &str) -> bool { +} + +fn is_ascii(v: &str) -> bool { +} + +fn contains(v: &str, pat: &str) -> bool { +} + +fn split_at(v: &str, index: usize) -> (&str, &str) { +} + +fn find(v: &str, pat: char) -> usize { +} +``` + +### Usage + +Here is a program to test your function + +```rust + +``` + +And its output + +```console +student@ubuntu:~/[[ROOT]]/test$ cargo run +student@ubuntu:~/[[ROOT]]/test$ +``` 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!( "{:?}",