mirror of https://github.com/01-edu/public.git
Augusto
4 years ago
4 changed files with 83 additions and 0 deletions
@ -0,0 +1,12 @@ |
|||||||
|
# This file is automatically @generated by Cargo. |
||||||
|
# It is not intended for manual editing. |
||||||
|
[[package]] |
||||||
|
name = "closures" |
||||||
|
version = "0.1.0" |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "closures_test" |
||||||
|
version = "0.1.0" |
||||||
|
dependencies = [ |
||||||
|
"closures", |
||||||
|
] |
@ -0,0 +1,10 @@ |
|||||||
|
[package] |
||||||
|
name = "closures_test" |
||||||
|
version = "0.1.0" |
||||||
|
authors = ["Augusto <aug.ornelas@gmail.com>"] |
||||||
|
edition = "2018" |
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||||
|
|
||||||
|
[dependencies] |
||||||
|
closures = { path = "../../../../rust-piscine-solutions/closures"} |
@ -0,0 +1,28 @@ |
|||||||
|
// Using closures and iterators create a function,
|
||||||
|
// first_fifty_even_square() that returns the
|
||||||
|
// first 50 pair numbers squares that it's [4, 16, 36, ..., 10000].
|
||||||
|
|
||||||
|
use closures::*; |
||||||
|
|
||||||
|
fn main() { |
||||||
|
println!("Hello, world!"); |
||||||
|
let v1 = first_fifty_even_square(); |
||||||
|
|
||||||
|
println!("All elements in {:?}, len = {}", v1, v1.len()); |
||||||
|
} |
||||||
|
|
||||||
|
#[cfg(test)] |
||||||
|
mod tests { |
||||||
|
use super::*; |
||||||
|
|
||||||
|
#[test] |
||||||
|
fn test() { |
||||||
|
let v1 = vec![ |
||||||
|
4, 16, 36, 64, 100, 144, 196, 256, 324, 400, 484, 576, 676, 784, 900, 1024, 1156, 1296, |
||||||
|
1444, 1600, 1764, 1936, 2116, 2304, 2500, 2704, 2916, 3136, 3364, 3600, 3844, 4096, |
||||||
|
4356, 4624, 4900, 5184, 5476, 5776, 6084, 6400, 6724, 7056, 7396, 7744, 8100, 8464, |
||||||
|
8836, 9216, 9604, 10000, |
||||||
|
]; |
||||||
|
assert_eq!(v1, first_fifty_even_square()); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,33 @@ |
|||||||
|
## closures |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Using closures and iterators create a function, `first_fifty_even_square` that returns the first 50 |
||||||
|
|
||||||
|
### Expected Functions |
||||||
|
|
||||||
|
```rust |
||||||
|
fn first_fifty_even_square() -> Vec<i32> { |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a program to test your function. |
||||||
|
|
||||||
|
```rust |
||||||
|
fn main() { |
||||||
|
println!("Hello, world!"); |
||||||
|
let v1 = first_fifty_even_square(); |
||||||
|
|
||||||
|
println!("All elements in {:?}, len = {}", v1, v1.len()); |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/[[ROOT]]/test$ cargo run |
||||||
|
All elements in [4, 16, 36, ..., 10000], len = 50 |
||||||
|
student@ubuntu:~/[[ROOT]]/test$ |
||||||
|
``` |
Loading…
Reference in new issue