From 299958c5efa601f47379db353a73d7eed1e58c3c Mon Sep 17 00:00:00 2001 From: Augusto Date: Mon, 18 Jan 2021 19:28:01 +0000 Subject: [PATCH] Add exercise subject for matrix_transposition_4by3 --- subjects/matrix_transposition/README.md | 2 +- subjects/matrix_transposition_4by3/README.md | 67 ++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 subjects/matrix_transposition_4by3/README.md diff --git a/subjects/matrix_transposition/README.md b/subjects/matrix_transposition/README.md index eaae796f..a1d479fe 100644 --- a/subjects/matrix_transposition/README.md +++ b/subjects/matrix_transposition/README.md @@ -13,7 +13,7 @@ Example: ``` -( a b ) __ transposition __> ( a d ) +( a b ) __ transposition __> ( a d ) ( c d ) ( b d ) ``` diff --git a/subjects/matrix_transposition_4by3/README.md b/subjects/matrix_transposition_4by3/README.md new file mode 100644 index 00000000..7b2ba7fe --- /dev/null +++ b/subjects/matrix_transposition_4by3/README.md @@ -0,0 +1,67 @@ +## matrix_transposition + +### Instructions + +- Define the structure matrix as a tuple of tuples of `i32`'s + +- Define a function that calculate 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 matrix `A'` where `A'`'s columns are `A`'s row and the rows are the columns: + +Example: + +``` +( a b ) __ transposition __> ( a d ) +( c d ) ( b d ) +``` + +- Matrix must implement Debug, PartialEq and Eq. You can use derive + +- Remember that you're defining a library so you have to make public the elements that are going to be called from an external crate. + +### Notions + +[Chapter 7]( https://doc.rust-lang.org/stable/book/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html ) + +### Expected Function + +```rust +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 posible program to test your function + +```rust +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 it's output: + +```console +student@ubuntu:~/[[ROOT]]/test$ 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)) +student@ubuntu:~/[[ROOT]]/test$ +```