mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xpetit
46f4ddc49e
|
4 years ago | |
---|---|---|
.. | ||
README.md |
README.md
matrix_transposition_4by3
Instructions
-
Define the structure matrix as a tuple of tuples of
i32
's -
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).
-
Note:
- The transpose of a matrix
A
is the matrixA'
whereA'
's columns areA
's row and the rows are the columns:
- The transpose of a matrix
Example:
( 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 )
-
Matrix must implement Debug, PartialEq and Eq. You can use derive.
-
Remember that a library has to be defined so the elements mube made public in order to be called from an external crate.
Notions
paths for referring to an item in the module tree
Expected Function and Structs
pub struct Matrix4by3(
pub (i32, i32, i32),
pub (i32, i32, i32),
pub (i32, i32, i32),
pub (i32, i32, i32),
);
pub struct Matrix3by4(
pub (i32, i32, i32, i32),
pub (i32, i32, i32, i32),
pub (i32, i32, i32, i32),
);
pub fn transpose(m: Matrix4by3) -> Matrix3by4 {
}
Usage
Here is a possible program to test your function,
fn main() {
let matrix = Matrix4by3((1, 2, 3), (4, 5, 6), (7, 8, 9), (10, 11, 12));
println!("Original matrix {:?}", matrix);
println!("Transpose matrix {:?}", transpose(matrix));
}
And its output:
$ cargo run
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))
$