Browse Source

Merge pull request #761 from 01-edu/rust-subject-review-quest-09

first pass quest 09 rust
pull/768/head
augusto-mantilla 4 years ago committed by GitHub
parent
commit
82c2dc0c31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      subjects/diamond_creation/README.md
  2. 20
      subjects/logic_number/README.md
  3. 6
      subjects/ordinal/README.md
  4. 14
      subjects/pangram/README.md
  5. 14
      subjects/pig_latin/README.md
  6. 24
      subjects/rgb_match/README.md
  7. 17
      subjects/rot/README.md
  8. 10
      subjects/scores/README.md
  9. 13
      subjects/searching/README.md
  10. 14
      subjects/spelling/README.md
  11. 6
      subjects/stars/README.md
  12. 14
      subjects/talking/README.md

16
subjects/diamond_creation/README.md

@ -2,7 +2,7 @@
### Instructions ### Instructions
Complete the function "make_diamond" that takes a letter as input, and outputs it in a diamond shape. Build the **function** `make_diamond` which takes a letter as input, and outputs it in a diamond shape.
Rules: Rules:
@ -17,12 +17,14 @@ Rules:
### Notions ### Notions
- https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html - [pattern syntax](https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html)
### Expected functions ### Expected functions
```rust ```rust
pub fn get_diamond(c: char) -> Vec<String> {} pub fn get_diamond(c: char) -> Vec<String> {
}
``` ```
### Usage ### Usage
@ -30,15 +32,15 @@ pub fn get_diamond(c: char) -> Vec<String> {}
Here is a program to test your function. Here is a program to test your function.
```rust ```rust
use diamond_creation::diamond_creation; use diamond_creation::*;
fn main() { fn main() {
println!("{:?}", make_diamond('A')); println!("{:?}", get_diamond('A'));
println!("{:?}", make_diamond('C')); println!("{:?}", get_diamond('C'));
} }
``` ```
And its output And its output:
```console ```console
student@ubuntu:~/[[ROOT]]/test$ cargo run student@ubuntu:~/[[ROOT]]/test$ cargo run

20
subjects/logic_number/README.md

@ -2,12 +2,10 @@
### Instructions ### Instructions
In this exercise it will be given an example of a sequence of numbers. In this exercise the logic of sequence of numbers will be tested.
For this you have to create a function `number_logic` which will take a number `u32` and return `true` if the number is the sum of its own digits, each raised to the power of the number of digits, and `false` otherwise.
Your purpose is to determinate if the sequence returns true or false. Examples:
For this you have to create a function `number_logic` that will take a number `u32` and return true if the number is the sum of its own digits, each raised to the power of the number of digits, and false otherwise.
Example:
- 9 returns true, because 9 = 9^1 = 9 - 9 returns true, because 9 = 9^1 = 9
- 10 returns false, because 10 != 1^2 + 0^2 = 1 - 10 returns false, because 10 != 1^2 + 0^2 = 1
@ -16,12 +14,14 @@ Example:
### Notions ### Notions
- https://doc.rust-lang.org/book/ch18-00-patterns.html - [patterns](https://doc.rust-lang.org/book/ch18-00-patterns.html)
### Expected functions ### Expected function
```rust ```rust
pub fn number_logic(num: u32) -> bool {} pub fn number_logic(num: u32) -> bool {
}
``` ```
### Usage ### Usage
@ -29,7 +29,7 @@ pub fn number_logic(num: u32) -> bool {}
Here is a program to test your function. Here is a program to test your function.
```rust ```rust
use logic_number::logic_number; use logic_number::*;
fn main() { fn main() {
let array = [9, 10, 153, 154]; let array = [9, 10, 153, 154];
@ -48,7 +48,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/ordinal/README.md

@ -7,7 +7,9 @@ Complete the function "num_to_ordinal" that receives a cardinal number and retur
### Expected functions ### Expected functions
```rust ```rust
pub fn num_to_ordinal(x: u32) -> String {} pub fn num_to_ordinal(x: u32) -> String {
}
``` ```
### Usage ### Usage
@ -15,7 +17,7 @@ pub fn num_to_ordinal(x: u32) -> String {}
Here is a program to test your function. Here is a program to test your function.
```rust ```rust
use ordinal::ordinal; use ordinal::*;
fn main() { fn main() {
println!("{}", num_to_ordinal(1)); println!("{}", num_to_ordinal(1));

14
subjects/pangram/README.md

@ -2,9 +2,9 @@
### Instructions ### Instructions
Determine if the string is a pangram. Create a `function` is_pangram which will determine whether or not a string is a pangram.
A pangram is a sentence using every letter of the alphabet at least once. A pangram is a sentence which uses every letter of the alphabet at least once.
Example: Example:
@ -12,12 +12,14 @@ Example:
### Notions ### Notions
- https://doc.rust-lang.org/book/ch18-00-patterns.html - [patterns](https://doc.rust-lang.org/book/ch18-00-patterns.html)
### Expected functions ### Expected functions
```rust ```rust
pub fn is_pangram(s: &str) -> bool {} pub fn is_pangram(s: &str) -> bool {
}
``` ```
### Usage ### Usage
@ -25,7 +27,7 @@ pub fn is_pangram(s: &str) -> bool {}
Here is a program to test your function. Here is a program to test your function.
```rust ```rust
use pangram::pangram; use pangram::*;
fn main() { fn main() {
println!( println!(
@ -36,7 +38,7 @@ fn main() {
} }
``` ```
And its output And its output:
```console ```console
student@ubuntu:~/[[ROOT]]/test$ cargo run student@ubuntu:~/[[ROOT]]/test$ cargo run

14
subjects/pig_latin/README.md

@ -2,22 +2,24 @@
### Instructions ### Instructions
Write a function that transforms a string passed as argument in its `Pig Latin` version. Write a **function** that transforms a string passed as argument in its `Pig Latin` version.
The rules used by Pig Latin are the following: The rules used by Pig Latin are the following:
- If a word begins with a vowel, just add "ay" to the end. - If a word begins with a vowel, just add "ay" to the end.
- If it begins with a consonant, then we take all consonants before the first vowel and we put them on the end of the word and add "ay" at the end. - If it begins with a consonant, then we take all consonants before the first vowel and we put them at the end of the word and add "ay" at the end.
- If a word starts with a consonant followed by "qu", move it to the end of the word, and then add an "ay" at the end. - If a word starts with a consonant followed by "qu", move it to the end of the word, and then add an "ay" at the end.
### Notions ### Notions
- https://doc.rust-lang.org/book/ch18-00-patterns.html - [patterns](https://doc.rust-lang.org/book/ch18-00-patterns.html)
### Expected functions ### Expected functions
```rust ```rust
pub fn pig_latin(text: &str) -> String {} pub fn pig_latin(text: &str) -> String {
}
``` ```
### Usage ### Usage
@ -25,7 +27,7 @@ pub fn pig_latin(text: &str) -> String {}
Here is a program to test your function. Here is a program to test your function.
```rust ```rust
use pig_latin::pig_latin; use pig_latin::*;
fn main() { fn main() {
println!("{}", pig_latin(&String::from("igloo"))); println!("{}", pig_latin(&String::from("igloo")));
@ -37,7 +39,7 @@ fn main() {
} }
``` ```
And its output And its output:
```console ```console
student@ubuntu:~/[[ROOT]]/test$ cargo run student@ubuntu:~/[[ROOT]]/test$ cargo run

24
subjects/rgb_match/README.md

@ -7,14 +7,23 @@ This function must allow you to swap the values of the struct.
### Notions ### Notions
- https://doc.rust-lang.org/book/ch18-00-patterns.html - [patterns](https://doc.rust-lang.org/book/ch18-00-patterns.html)
### Expected functions ### Expected functions
```rust ```rust
pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}
impl Color { impl Color {
pub fn swap(mut self, first: u8, second: u8) -> Color {} pub fn swap(mut self, first: u8, second: u8) -> Color {
} }
}
``` ```
### Usage ### Usage
@ -22,14 +31,7 @@ impl Color {
Here is a program to test your function. Here is a program to test your function.
```rust ```rust
use rgb_match::rgb_match; use rgb_match::*;
struct Color {
r: u8,
g: u8,
b: u8,
a: u8,
}
fn main() { fn main() {
let c = Color { let c = Color {
@ -57,7 +59,7 @@ fn main() {
} }
``` ```
And its output And its output:
```console ```console
student@ubuntu:~/[[ROOT]]/test$ cargo run student@ubuntu:~/[[ROOT]]/test$ cargo run

17
subjects/rot/README.md

@ -2,7 +2,7 @@
### Instructions ### Instructions
By now you will have the knowledge of the so called rotational cipher "ROT13". In this exercise, if you do not know about it already, you will learn about the rotational cipher "ROT13".
A ROT13 on the Latin alphabet would be as follows: A ROT13 on the Latin alphabet would be as follows:
@ -12,19 +12,21 @@ A ROT13 on the Latin alphabet would be as follows:
Your purpose in this exercise is to create a similar `rotate` function that is a better version of the ROT13 cipher. Your purpose in this exercise is to create a similar `rotate` function that is a better version of the ROT13 cipher.
Your function will receive a string and a number and it will rotate each letter of that string the number of times settled by the second argument to the right, or to the left if the number are negative. Your function will receive a `string` and a `number` and it will rotate each letter of that `string` by the `number` of times settled by the second argument towards the right, or towards the left if the number is negative.
Your function should only change letters. If the string includes punctuation and numbers Your `function` should only rotate letters. If the string includes punctuation and numbers
they will remain the same. they will remain the same.
### Notions ### Notions
- https://doc.rust-lang.org/book/ch18-00-patterns.html - [patterns](https://doc.rust-lang.org/book/ch18-00-patterns.html)
### Expected functions ### Expected functions
```rust ```rust
pub fn rotate(input: &str, key: i8) -> String {} pub fn rotate(input: &str, key: i8) -> String {
}
``` ```
### Usage ### Usage
@ -32,7 +34,7 @@ pub fn rotate(input: &str, key: i8) -> String {}
Here is a program to test your function. Here is a program to test your function.
```rust ```rust
use rot::rot; use rot::*;
fn main() { fn main() {
@ -58,7 +60,7 @@ fn main() {
} }
``` ```
And its output And its output:
```console ```console
student@ubuntu:~/[[ROOT]]/test$ cargo run student@ubuntu:~/[[ROOT]]/test$ cargo run
@ -72,6 +74,5 @@ The decoded message is: Ryg aesmuvi nkpd tewzsxq jolbkc foh
Your cypher wil be: Xiwxmrk amxl ryqfivw 1 2 3 Your cypher wil be: Xiwxmrk amxl ryqfivw 1 2 3
Your cypher wil be: Fqefuzs Your cypher wil be: Fqefuzs
The letter "a" becomes: z The letter "a" becomes: z
student@ubuntu:~/[[ROOT]]/test$ student@ubuntu:~/[[ROOT]]/test$
``` ```

10
subjects/scores/README.md

@ -8,7 +8,7 @@ Create a function `score` that given a string, computes the score for that given
Each letter has their value, you just have to sum the values of the letters in the Each letter has their value, you just have to sum the values of the letters in the
given string. given string.
You'll need these: You will need these:
| Letter | Value | | Letter | Value |
| ---------------------------- | :---: | | ---------------------------- | :---: |
@ -22,12 +22,14 @@ You'll need these:
### Notions ### Notions
- https://doc.rust-lang.org/book/ch18-00-patterns.html - [patterns](https://doc.rust-lang.org/book/ch18-00-patterns.html)
### Expected functions ### Expected functions
```rust ```rust
pub fn score(word: &str) -> u64 {} pub fn score(word: &str) -> u64 {
}
``` ```
### Usage ### Usage
@ -35,7 +37,7 @@ pub fn score(word: &str) -> u64 {}
Here is a program to test your function. Here is a program to test your function.
```rust ```rust
use scores::scores; use scores::*;
fn main() { fn main() {
println!("{}", score("a")); println!("{}", score("a"));

13
subjects/searching/README.md

@ -3,17 +3,20 @@
### Instructions ### Instructions
In this exercise you will have to complete the function `search`. In this exercise you will have to complete the function `search`.
this function receives an array and a key of `i32`, then it will return the position This **function** receives an array and a key of `i32`, then it will return the position
of the given key in the array. of the given key in the array.
Only arrays with uniques keys will be tested.
### Notions ### Notions
- https://doc.rust-lang.org/book/ch18-00-patterns.html - [patterns](https://doc.rust-lang.org/book/ch18-00-patterns.html)
### Expected functions ### Expected functions
```rust ```rust
pub fn search(array: &[i32], key: i32) -> Option<usize> {} pub fn search(array: &[i32], key: i32) -> Option<usize> {
}
``` ```
### Usage ### Usage
@ -21,7 +24,7 @@ pub fn search(array: &[i32], key: i32) -> Option<usize> {}
Here is a program to test your function. Here is a program to test your function.
```rust ```rust
use searching::searching; use searching::*;
fn main() { fn main() {
let ar = [1, 3, 4, 6, 8, 9, 11]; let ar = [1, 3, 4, 6, 8, 9, 11];
@ -33,7 +36,7 @@ fn main() {
} }
``` ```
And its output And its output:
```console ```console
student@ubuntu:~/[[ROOT]]/test$ cargo run student@ubuntu:~/[[ROOT]]/test$ cargo run

14
subjects/spelling/README.md

@ -16,14 +16,18 @@ So, if the program generates the number:
- 1002 your function will return the string "one thousand two". - 1002 your function will return the string "one thousand two".
- 1000000 your function will return the string "one million" - 1000000 your function will return the string "one million"
Only positive numbers will be tested. (Up to a million).
### Notions ### Notions
- https://doc.rust-lang.org/book/ch18-00-patterns.html - [patterns](https://doc.rust-lang.org/book/ch18-00-patterns.html)
### Expected functions ### Expected function
```rust ```rust
pub fn spell(n: u64) -> String {} pub fn spell(n: u64) -> String {
}
``` ```
### Usage ### Usage
@ -31,7 +35,7 @@ pub fn spell(n: u64) -> String {}
Here is a program to test your function. Here is a program to test your function.
```rust ```rust
use spelling::spelling; use spelling::*;
fn main() { fn main() {
println!("{}", spell(348)); println!("{}", spell(348));
@ -39,7 +43,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/stars/README.md

@ -8,7 +8,9 @@ parameter and returns a string of stars (asterisks) 2^n long (2 to the nth power
### Expected functions ### Expected functions
```rust ```rust
pub fn stars(n: u32) -> String {} pub fn stars(n: u32) -> String {
}
``` ```
### Usage ### Usage
@ -25,7 +27,7 @@ fn main() {
} }
``` ```
And its output And its output:
```console ```console
student@ubuntu:~/[[ROOT]]/test$ cargo run student@ubuntu:~/[[ROOT]]/test$ cargo run

14
subjects/talking/README.md

@ -2,12 +2,12 @@
### Instructions ### Instructions
Build the function `talking` that will allow you to talk with your computer. Build the function `talking` which will allow you to talk with your computer.
His answers will be created by you following the rules below. His answers will be created by you following the rules below.
- He answers "There is no need to yell, calm down!" if you yell at him, for example "LEAVE ME ALONE!" - He answers "There is no need to yell, calm down!" if you yell at him, for example "LEAVE ME ALONE!"
(it is consider yelling when the sentence is all written in capital letters). (it is considered yelling when the sentence is all written in capital letters).
- He answers "Sure" if you ask him something without yelling, for example "Is everything ok with you?" - He answers "Sure" if you ask him something without yelling, for example "Is everything ok with you?"
- He answers "Quiet, I am thinking!" if you yell a question at him. "HOW ARE YOU?" - He answers "Quiet, I am thinking!" if you yell a question at him. "HOW ARE YOU?"
- He says "Just say something!" if you address him without actually saying anything. - He says "Just say something!" if you address him without actually saying anything.
@ -15,12 +15,14 @@ His answers will be created by you following the rules below.
### Notions ### Notions
- https://doc.rust-lang.org/book/ch18-00-patterns.html - [patterns](https://doc.rust-lang.org/book/ch18-00-patterns.html)
### Expected functions ### Expected functions
```rust ```rust
pub fn talking(text: &str) -> &str {} pub fn talking(text: &str) -> &str {
}
``` ```
### Usage ### Usage
@ -28,7 +30,7 @@ pub fn talking(text: &str) -> &str {}
Here is a program to test your function. Here is a program to test your function.
```rust ```rust
use talking::talking; use talking::*;
fn main() { fn main() {
println!("{:?}", talking("JUST DO IT!")); println!("{:?}", talking("JUST DO IT!"));
@ -39,7 +41,7 @@ fn main() {
} }
``` ```
And its output And its output:
```console ```console
student@ubuntu:~/[[ROOT]]/test$ cargo run student@ubuntu:~/[[ROOT]]/test$ cargo run

Loading…
Cancel
Save