From 6c6eb77480279a776a93c68e23e20fcbbe475e52 Mon Sep 17 00:00:00 2001 From: Luke Tidd Date: Wed, 10 May 2023 16:47:23 -0400 Subject: [PATCH] updates --- class/ex1/Cargo.toml | 8 ++++++++ class/ex1/src/main.rs | 45 +++++++++++++++++++++++++++++++++++++++++++ class/notes | 2 ++ 3 files changed, 55 insertions(+) create mode 100644 class/ex1/Cargo.toml create mode 100644 class/ex1/src/main.rs diff --git a/class/ex1/Cargo.toml b/class/ex1/Cargo.toml new file mode 100644 index 0000000..49f4ddc --- /dev/null +++ b/class/ex1/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "pretty_print" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/class/ex1/src/main.rs b/class/ex1/src/main.rs new file mode 100644 index 0000000..7485962 --- /dev/null +++ b/class/ex1/src/main.rs @@ -0,0 +1,45 @@ +// TODO: remove this when you're done with your implementation. +#![allow(unused_variables, dead_code)] + +fn transpose(matrix: [[i32; 3]; 3]) -> [[i32; 3]; 3] { +/* +[[matrix[0][0],matrix[1][0],matrix[2][0]], +[matrix[0][1],matrix[1][1],matrix[2][1]], +[matrix[0][2],matrix[1][2],matrix[2][2]]] +*/ + let mut temp: [[i32; 3]; 3] = [0; 3]; 3] + for row in 0..3 { // has additional bounds checks +// for row in matrix { +// println : +// } + for col in 0..3 { + transposed[col][row] = matrix[row][col]; + } + } + transposed +} + +fn pretty_print(matrix: &[[i32; 3]; 3]) { + for x in 0..3 { + print!("["); + for y in 0..3 { + print!("{} ", &matrix[x][y]); + } + print!("]\n"); + } +} + +fn main() { + let matrix = [ + [101, 102, 103], // <-- the comment makes rustfmt add a newline + [201, 202, 203], + [301, 302, 303], + ]; + + println!("matrix:"); + pretty_print(&matrix); + + let transposed = transpose(matrix); + println!("transposed:"); + pretty_print(&transposed); +} diff --git a/class/notes b/class/notes index beac4fc..e0cbffe 100644 --- a/class/notes +++ b/class/notes @@ -158,3 +158,5 @@ traits! type conversions in a generic way x.into() will do the type conversion for you, if valid and lossless + +