2021-01-19 17:29:11 +00:00
## matrix_transposition_4by3
2021-01-18 19:28:01 +00:00
### Instructions
- Define the structure matrix as a tuple of tuples of `i32` 's
2021-03-23 16:02:47 +00:00
- Define a **function** which calculates the transpose matrix of a 4x3 matrix (4 rows by 3 columns) which is a 3x4 matrix (3 rows by 4 columns).
2021-01-18 19:28:01 +00:00
- Note:
2021-03-23 15:03:35 +00:00
- The transpose of a matrix `A` is the matrix `A'` where `A'` 's columns are `A` 's row and the rows are the columns:
2021-01-18 19:28:01 +00:00
Example:
2021-03-23 15:03:35 +00:00
```console
2021-01-19 17:29:11 +00:00
( a b c ) __ transposition __ > ( a d g j )
( d e f ) ( b e h k )
( g h i ) ( c f i l )
( j k l )
2021-01-18 19:28:01 +00:00
```
2021-03-23 16:02:47 +00:00
- Matrix must implement Debug, PartialEq and Eq. You can use derive.
2021-01-18 19:28:01 +00:00
2021-03-23 16:02:47 +00:00
- Remember that a library has to be defined so the elements mube made public in order to be called from an external crate.
2021-01-18 19:28:01 +00:00
### Notions
2021-03-23 16:02:47 +00:00
[paths for referring to an item in the module tree ](https://doc.rust-lang.org/stable/book/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html )
2021-01-18 19:28:01 +00:00
2021-01-19 17:29:11 +00:00
### Expected Function and Structs
2021-01-18 19:28:01 +00:00
```rust
pub struct Matrix4by3(
2021-03-23 15:03:35 +00:00
pub (i32, i32, i32),
pub (i32, i32, i32),
pub (i32, i32, i32),
pub (i32, i32, i32),
2021-01-18 19:28:01 +00:00
);
pub struct Matrix3by4(
2021-03-23 15:03:35 +00:00
pub (i32, i32, i32, i32),
pub (i32, i32, i32, i32),
pub (i32, i32, i32, i32),
2021-01-18 19:28:01 +00:00
);
pub fn transpose(m: Matrix4by3) -> Matrix3by4 {
2021-03-23 16:02:47 +00:00
2021-01-18 19:28:01 +00:00
}
```
### Usage
2021-03-23 16:02:47 +00:00
Here is a possible program to test your function,
2021-01-18 19:28:01 +00:00
```rust
fn main() {
2021-03-23 15:03:35 +00:00
let matrix = Matrix4by3((1, 2, 3), (4, 5, 6), (7, 8, 9), (10, 11, 12));
2021-01-18 19:28:01 +00:00
println!("Original matrix {:?}", matrix);
println!("Transpose matrix {:?}", transpose(matrix));
}
```
2021-03-23 15:03:35 +00:00
And its output:
2021-01-18 19:28:01 +00:00
```console
2021-04-28 09:47:34 +00:00
$ cargo run
2021-01-18 19:28:01 +00:00
Original matrix Matrix4by3((1, 2, 3), (4, 5, 6), (7, 8, 9), (10, 11, 12))
Transpose matrix Matrix3by4((1, 4, 7, 10), (2, 5, 8, 11), (3, 6, 9, 12))
2021-04-28 09:47:34 +00:00
$
2021-01-18 19:28:01 +00:00
```