matrices and transposing. Also compiling dead code
This commit is contained in:
parent
4247c43b1b
commit
baec55b750
44
src/main.rs
44
src/main.rs
|
@ -1,14 +1,40 @@
|
|||
fn main() {
|
||||
let a: [i32; 3] = [1, 2, 3];
|
||||
let x: i8 = 15;
|
||||
let y: i16 = 1000;
|
||||
// TODO
|
||||
#![allow(unused_variables, dead_code)]
|
||||
|
||||
for i in a {
|
||||
println!("{}", i);
|
||||
println!("i * x * y = {}", multiply(i.into(), x.into(), y.into()));
|
||||
fn interesting() -> i32 {
|
||||
// this code compiles and doesn't complain about being unused or not returning the correct
|
||||
// thing, but will hit a runtime error if/when this is called
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn transpose(matrix: [[i32; 3]; 3]) -> [[i32; 3]; 3] {
|
||||
let matrix_new = [
|
||||
[matrix[0][0], matrix[1][0], matrix[2][0]], // newline
|
||||
[matrix[0][1], matrix[1][1], matrix[2][1]],
|
||||
[matrix[0][2], matrix[1][2], matrix[2][2]],
|
||||
];
|
||||
return matrix_new;
|
||||
}
|
||||
|
||||
fn pretty_print(matrix: &[[i32; 3]; 3]) {
|
||||
println!("[");
|
||||
for row in matrix {
|
||||
println!(" [ {} {} {} ]", row[0], row[1], row[2]);
|
||||
}
|
||||
println!("]");
|
||||
}
|
||||
|
||||
fn multiply(a: i32, x: i32, y: i32) -> i32 {
|
||||
return a * x * y;
|
||||
fn main() {
|
||||
let matrix = [
|
||||
[101, 102, 103], // we want the newline here
|
||||
[201, 202, 203],
|
||||
[301, 302, 303],
|
||||
];
|
||||
|
||||
println!("matrix:");
|
||||
pretty_print(&matrix);
|
||||
|
||||
let transposed = transpose(matrix);
|
||||
println!("transposed:");
|
||||
pretty_print(&transposed);
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue