Browse Source

1) renaming of string_literal folder with an extra s to fix the fetching problem

2) added notions to arrange_it
3) reorganized tic tac toe
pull/710/head
Chris 3 years ago
parent
commit
8002cfd522
  1. 16
      subjects/arrange_it/README.md
  2. 12
      subjects/string_literal/README.md
  3. 53
      subjects/string_literals/README.md
  4. 30
      subjects/tic_tac_toe/README.md

16
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"));
}
```

12
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)

53
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$
```

30
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<Vec<&str>>) 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<Vec<&str>>).
- 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<Vec<&str>>) -> String {
pub fn tic_tac_toe(table: Vec<Vec<&str>>) -> String {
}
fn diagonals(player: &str, table: &Vec<Vec<&str>>) -> bool {
pub fn diagonals(player: &str, table: &Vec<Vec<&str>>) -> bool {
}
fn horizontal(player: &str, table: &Vec<Vec<&str>>) -> bool {
pub fn horizontal(player: &str, table: &Vec<Vec<&str>>) -> bool {
}
fn vertical(player: &str, table: &Vec<Vec<&str>>) -> bool {
pub fn vertical(player: &str, table: &Vec<Vec<&str>>) -> bool {
}
```
@ -36,6 +44,8 @@ fn vertical(player: &str, table: &Vec<Vec<&str>>) -> bool {
Here is a program to test your function
```rust
use tic_tac_toe::*;
fn main() {
println!(
"{:?}",

Loading…
Cancel
Save