|
|
@ -2,17 +2,25 @@ |
|
|
|
|
|
|
|
|
|
|
|
### Instructions |
|
|
|
### Instructions |
|
|
|
|
|
|
|
|
|
|
|
Your objective is to fix the program so that all functions work. |
|
|
|
Your objective is to fix the **functions** work so that the program works. |
|
|
|
|
|
|
|
|
|
|
|
- `nbr_function`, returns a tuple with the original value, the exponential and logarithm of that value |
|
|
|
- `nbr_function` returns a tuple: |
|
|
|
- `str_function`, returns a tuple with the original value and the exponential of that value as a string |
|
|
|
- with the `original` value |
|
|
|
- `vec_function`, returns a tuple with the original value and the logarithm of each value |
|
|
|
- the `exponential function` of the value |
|
|
|
|
|
|
|
- and the `natural logarithm` of this `absolute` value |
|
|
|
|
|
|
|
- `str_function` returns a tuple: |
|
|
|
|
|
|
|
- with the `original` value |
|
|
|
|
|
|
|
- and the `exponential function` each value as a string (see the example) |
|
|
|
|
|
|
|
- `vec_function` returns a tuple: |
|
|
|
|
|
|
|
- with the `original` value |
|
|
|
|
|
|
|
- and the `natural logarithm` of each `absolute` value |
|
|
|
|
|
|
|
|
|
|
|
The objective is to now how ownership works with different types. |
|
|
|
The objective is to know how ownership works with different types. |
|
|
|
|
|
|
|
|
|
|
|
### Notions |
|
|
|
### Notions |
|
|
|
|
|
|
|
|
|
|
|
- https://doc.rust-lang.org/rust-by-example/scope/move.html |
|
|
|
- [scope](https://doc.rust-lang.org/rust-by-example/scope/move.html) |
|
|
|
|
|
|
|
- [Primitive Type f64](https://doc.rust-lang.org/std/primitive.f64.html) |
|
|
|
|
|
|
|
|
|
|
|
### Expected Functions |
|
|
|
### Expected Functions |
|
|
|
|
|
|
|
|
|
|
@ -32,18 +40,21 @@ pub fn vec_function(b: Vec<u32>) -> (Vec<u32>, Vec<f64>) { |
|
|
|
Here is a possible program to test your function : |
|
|
|
Here is a possible program to test your function : |
|
|
|
|
|
|
|
|
|
|
|
```rust |
|
|
|
```rust |
|
|
|
|
|
|
|
use copy::*; |
|
|
|
|
|
|
|
|
|
|
|
fn main() { |
|
|
|
fn main() { |
|
|
|
let a = String::from("1 2 4 5 6"); |
|
|
|
let a: u32 = 0; |
|
|
|
let b = vec![1, 2, 4, 5]; |
|
|
|
let b = String::from("1 2 4 5 6"); |
|
|
|
let c: u32 = 0; |
|
|
|
let c = vec![1, 2, 4, 5]; |
|
|
|
|
|
|
|
|
|
|
|
println!("{:?}", nbr_function(c)); |
|
|
|
println!("{:?}", nbr_function(a)); |
|
|
|
// output: (12, 162754.79141900392, 2.4849066497880004) |
|
|
|
// output : (0, 1.0, inf) |
|
|
|
println!("{:?}", vec_function(b)); |
|
|
|
println!("{:?}", str_function(b)); |
|
|
|
// output: ([1, 2, 4], [0.0, 0.6931471805599453, 1.3862943611198906]) |
|
|
|
// output : ("1 2 4 5 6", "2.718281828459045 7.38905609893065 54.598150033144236 148.4131591025766 403.4287934927351") |
|
|
|
println!("{:?}", str_function(a)); |
|
|
|
println!("{:?}", vec_function(c)); |
|
|
|
// output: ("1 2 4", "2.718281828459045 7.38905609893065 54.598150033144236") |
|
|
|
// output : ([1, 2, 4, 5], [0.0, 0.6931471805599453, 1.3862943611198906, 1.6094379124341003]) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
And its output: |
|
|
|
And its output: |
|
|
@ -51,7 +62,7 @@ And its output: |
|
|
|
```console |
|
|
|
```console |
|
|
|
student@ubuntu:~/[[ROOT]]/test$ cargo run |
|
|
|
student@ubuntu:~/[[ROOT]]/test$ cargo run |
|
|
|
(0, 1.0, inf) |
|
|
|
(0, 1.0, inf) |
|
|
|
([1, 2, 4, 5], [0.0, 0.6931471805599453, 1.3862943611198906, 1.6094379124341003]) |
|
|
|
|
|
|
|
("1 2 4 5 6", "2.718281828459045 7.38905609893065 54.598150033144236 148.4131591025766 403.4287934927351") |
|
|
|
("1 2 4 5 6", "2.718281828459045 7.38905609893065 54.598150033144236 148.4131591025766 403.4287934927351") |
|
|
|
|
|
|
|
([1, 2, 4, 5], [0.0, 0.6931471805599453, 1.3862943611198906, 1.6094379124341003]) |
|
|
|
student@ubuntu:~/[[ROOT]]/test$ |
|
|
|
student@ubuntu:~/[[ROOT]]/test$ |
|
|
|
``` |
|
|
|
``` |
|
|
|