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.
davhojt
2f50e3c413
|
2 years ago | |
---|---|---|
.. | ||
README.md | 2 years ago |
README.md
matrix_transposition
Instructions
-
Define a
struct
namedMatrix
as a tuple of 2 tuples. The nested tuple will contain 2i32
s. -
Create a function named
transpose
that calculates the transposition of a 2x2 matrix.
pub fn transpose(m: Matrix) -> Matrix {
}
The transposition of a matrix, switches the columns to rows, and the rows to columns. For example:
( a b ) __ transposition __> ( a c )
( c d ) ( b d )
Matrix
must implement Debug
, PartialEq
and Eq
. You can use derive
.
Remember that you are defining a library, so any element that can be called from an external crate must be made public.
Usage
Here is a possible program to test your function
use matrix_transposition::transpose;
use matrix_transposition::Matrix;
fn main() {
let matrix = Matrix((1, 3), (4, 5));
println!("Original matrix {:?}", matrix);
println!("Transpose matrix {:?}", transpose(matrix));
}
And its output:
$ cargo run
Original matrix Matrix((1, 3), (4, 5))
Transpose matrix Matrix((1, 4), (3, 5))
$