Browse Source

proposed improvements

content-update
Chris 3 years ago
parent
commit
1dd6564242
  1. 33
      subjects/arrays/README.md
  2. 42
      subjects/card_deck/README.md
  3. 35
      subjects/circle/README.md
  4. 8
      subjects/edit_distance/README.md
  5. 6
      subjects/strings/README.md

33
subjects/arrays/README.md

@ -2,20 +2,27 @@
### Instructions ### 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() Define a **function** called `thirtytwo_tens` that returns an array with 32 positions filled with only the value `10`:
= 32
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 ### 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 ```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. 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 ```rust
use arrays::{sum, thirtytwo_tens}; use arrays::{sum, thirtytwo_tens};
fn main() { fn main() {
let a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; let a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let a1: Vec<i32> = (1..11).; let a1: Vec<i32> = (1..11).; //missing info here
let b = [_; 10]; let b = [_; 10]; //missing info here
println!("The Sum of the elements in {:?} = {}", a, sum(a)); println!("The Sum of the elements in {:?} = {}", a, sum(a));//missing info here
println!("The Sum of the elements in {:?} = ", a1, sum(a1)); println!("The Sum of the elements in {:?} = ", a1, sum(a1));//missing info here
println!("The Sum of the elements in {:?} = {}", b, sum(b)); println!("The Sum of the elements in {:?} = {}", b, sum(b));//missing info here
println!( println!(
"Array size {} with only 10's in it {:?}", "Array size {} with only 10's in it {:?}",
thirtytwo_tens().len(), thirtytwo_tens().len(),
@ -44,7 +51,7 @@ fn main() {
} }
``` ```
And its output And its output:
```console ```console
student@ubuntu:~/[[ROOT]]/test$ cargo run student@ubuntu:~/[[ROOT]]/test$ cargo run

42
subjects/card_deck/README.md

@ -2,32 +2,30 @@
### Instructions ### Instructions
Represent cards from a desk A standard deck of cards has 52 cards: 4 suits and 13 cards per suit.
Represent the cards from a deck:
- 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`)
- 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 - Then create the `Rank` enum that can have the value
`Ace`, `King`, `Queen`, `Jack`, and `Number` associated to an `u8` `Ace`, `King`, `Queen`, `Jack`, and `Number` associated to an `u8`
value to represent the ranks 2 through 10 value to represent the ranks 2 through 10
After create an associated function to `Rank` called `Random` that - After create an associated **function** to `Rank` called `Random` that
returns a random `Rank` returns a random `Rank`
- Finally create a structure name `Card` which has the fields `suit` - Finally create a structure name `Card` which has the fields `suit`
and `rank` and `rank`
Define: Define:
The associated function `translate` for Rank and Suite - The associated **function** `transpose` for `Rank` and `Suit`:
- 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 `Suit`, `transpose_suit` 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) - For `Rank`, `transpose_rank` 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 ### Expected Functions and Structures
@ -35,13 +33,13 @@ Finally define the function `winner_card` that returns true if the card passed a
pub fn random() -> Suit { pub fn random() -> Suit {
} }
pub fn translate(value: u8) -> Suit { pub fn transpose_suit(value: u8) -> Suit {
} }
pub fn random() -> Rank { pub fn random() -> Rank {
} }
pub fn traslate(value: u8) -> Rank { pub fn transpose_rank(value: u8) -> Rank {
} }
pub enum Suit { pub enum Suit {
@ -67,7 +65,7 @@ fn main() {
suit: Suit::random(), 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" // Now if the card is an Ace of Spades print "You are the winner"
if card_deck::winner_card(your_card) { if card_deck::winner_card(your_card) {
@ -80,6 +78,6 @@ And its output
```console ```console
student@ubuntu:~/[[ROOT]]/test$ cargo run 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$ student@ubuntu:~/[[ROOT]]/test$
``` ```

35
subjects/circle/README.md

@ -2,22 +2,27 @@
### Instructions ### Instructions
Create the structures `Circle` and `Point` and the methods necessary for the code in [usage](#usage) to compile and run giving the expected output. 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: Methods:
- Point;
distance() - Point:
- Circle: distance() -> returns the distance between two coordinates
diameter -> returns the diameter of the circle - Circle:
area -> returns the area of the circle diameter() -> returns the diameter of the circle
intersection -> returns true if the 2 circles intersect area() -> returns the area of the circle
Associated Functions intersect() -> which returns true, if the 2 circles in parameters intersect
- Circle: Associated Functions
new -> receives three 64 bits floating point numbers in the following - Circle:
order: x, y and radius (x and y are the coordinates of the center). new() -> receives three 64 bits floating point numbers in the following
and returns a new circle order: x, y and radius (x and y are the coordinates of the center).
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 ### Expected Functions and Structures
This snippets are incomplete and it is part of the exercise to discover how to complete them. This snippets are incomplete and it is part of the exercise to discover how to complete them.
@ -29,7 +34,7 @@ struct Circle {
} }
struct Point { struct Point {
// ... // ...
} }
// Point // Point

8
subjects/edit_distance/README.md

@ -2,7 +2,7 @@
### Instructions ### 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 ### Expected Function
@ -13,13 +13,15 @@ pub fn edit_distance(source: &str, target: &str) -> usize {
### Notions ### 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 ### Usage
Here is a program to test your function. Here is a program to test your function.
```rust ```rust
use edit_distance::*;
fn main() { fn main() {
let source = "alignment"; let source = "alignment";
let target = "assignment"; let target = "assignment";
@ -32,7 +34,7 @@ fn main() {
} }
``` ```
And its output And its output:
```console ```console
student@ubuntu:~/[[ROOT]]/test$ cargo run student@ubuntu:~/[[ROOT]]/test$ cargo run

6
subjects/strings/README.md

@ -2,12 +2,12 @@
### Instructions ### 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 ### Expected Function
```rust ```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. Here is a program to test your function.
```rust ```rust
use strings::*;
fn main() { fn main() {
println!("length of {} = {}", "❤", char_length("❤")); println!("length of {} = {}", "❤", char_length("❤"));
println!("length of {} = {}", "形声字", char_length("形聲字")); println!("length of {} = {}", "形声字", char_length("形聲字"));

Loading…
Cancel
Save