From 1dd6564242028c4e3c03f93f461f8e6d2e5cb153 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 10 Feb 2021 02:04:54 +0000 Subject: [PATCH] proposed improvements --- subjects/arrays/README.md | 33 +++++++++++++++---------- subjects/card_deck/README.md | 42 +++++++++++++++----------------- subjects/circle/README.md | 35 ++++++++++++++------------ subjects/edit_distance/README.md | 8 +++--- subjects/strings/README.md | 6 +++-- 5 files changed, 69 insertions(+), 55 deletions(-) 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/card_deck/README.md b/subjects/card_deck/README.md index 3d3a6c27..be8287a8 100644 --- a/subjects/card_deck/README.md +++ b/subjects/card_deck/README.md @@ -2,32 +2,30 @@ ### 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** `transpose` for `Rank` and `Suit`: + - 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`, `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 @@ -35,13 +33,13 @@ Finally define the function `winner_card` that returns true if the card passed a pub fn random() -> Suit { } -pub fn translate(value: u8) -> Suit { +pub fn transpose_suit(value: u8) -> Suit { } pub fn random() -> Rank { } -pub fn traslate(value: u8) -> Rank { +pub fn transpose_rank(value: u8) -> Rank { } pub enum Suit { @@ -67,7 +65,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 +78,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/circle/README.md b/subjects/circle/README.md index 84add0c1..35e48c20 100644 --- a/subjects/circle/README.md +++ b/subjects/circle/README.md @@ -2,22 +2,27 @@ ### 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: - - 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 - - + +- 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 the 2 circles in parameters 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). + 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 is part of the exercise to discover how to complete them. @@ -29,7 +34,7 @@ struct Circle { } struct Point { -// ... +// ... } // Point 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/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("形聲字"));