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**`translate` 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`, `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 tranlation between an integer value (u8) and the rank ( 1 -> Ace, 2 -> 2, .., 10 -> 10, 11 -> Jack, 12 -> Queen, 13 -> King)
- 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
### Expected Functions and Structures
```rust
```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 {
pub struct Card {
@ -67,7 +69,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"
Create the structures `Circle` and `Point` and the methods necessary for the code in [usage](#usage) to compile and run giving the expected result.
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()
- 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
#### 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
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.
Implement the function bubble_sort which receives a vector Vec<i32> and return the same vector but in increasing order using the bubble sort algorithm
Implement the **function**`bubble_sort` which receives a vector Vec<i32> and returns the same vector but in increasing order using the bubble sort algorithm.
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`.
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.