diff --git a/README.md b/README.md index 417a7a2..a632e54 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ We encourage you to share your progress and ask questions in the Discussions sec | Day #41 | [Sales By Match](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-06/Day-41_Sales-By-Match) | :white_check_mark: | | Day #42 | [Drawing Book](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-06/Day-42_Drawing-Book) | :white_check_mark: | | Day #43 | [Area Of A Triangle](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-07/Day-43_Area-Of-A-Triangle) | :white_check_mark: | -| Day #44 | [Maximum Edge Of A Triangle](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-07/Day-44_Maximum-Edge-Of-A-Triangle) | :white_large_square: | +| Day #44 | [Maximum Edge Of A Triangle](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-07/Day-44_Maximum-Edge-Of-A-Triangle) | :white_check_mark: | | Day #45 | [Subtract The Swapped Bits...](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-07/Day-45_Subtract-The-Swapped-Bits-Without-Temp-Storage) | :white_large_square: | | Day #46 | [Hot Pics Of Danny Devito](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-07/Day-46_Hot-Pics-Of-Danny-Devito) | :white_large_square: | | Day #47 | [Zip It](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-07/Day-47_Zip-It) | :white_large_square: | diff --git a/Week-07/Day-44_Maximum-Edge-Of-A-Triangle/day44/Cargo.toml b/Week-07/Day-44_Maximum-Edge-Of-A-Triangle/day44/Cargo.toml new file mode 100644 index 0000000..616400a --- /dev/null +++ b/Week-07/Day-44_Maximum-Edge-Of-A-Triangle/day44/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "day44" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/Week-07/Day-44_Maximum-Edge-Of-A-Triangle/day44/src/lib.rs b/Week-07/Day-44_Maximum-Edge-Of-A-Triangle/day44/src/lib.rs new file mode 100644 index 0000000..a959945 --- /dev/null +++ b/Week-07/Day-44_Maximum-Edge-Of-A-Triangle/day44/src/lib.rs @@ -0,0 +1,3 @@ +pub fn next_edge(side1: usize, side2: usize) -> usize { + side1 + side2 - 1 +} diff --git a/Week-07/Day-44_Maximum-Edge-Of-A-Triangle/day44/src/main.rs b/Week-07/Day-44_Maximum-Edge-Of-A-Triangle/day44/src/main.rs new file mode 100644 index 0000000..4074a17 --- /dev/null +++ b/Week-07/Day-44_Maximum-Edge-Of-A-Triangle/day44/src/main.rs @@ -0,0 +1,38 @@ +use std::{ + io::{self, Write}, + process::exit, +}; + +use day44::next_edge; + +pub fn read_usize(request: &str) -> Result { + print!("{}", request); + io::stdout().flush().expect("Failed to flush stdout"); + let mut buffer = String::new(); + std::io::stdin() + .read_line(&mut buffer) + .expect("Failed to read input"); + buffer.trim().parse() +} + +fn main() { + let side1 = match read_usize("Enter the length of the first side of the triangle: ") { + Ok(n) => n, + Err(e) => { + eprintln!("Error: {}", e); + exit(1); + } + }; + let side2 = match read_usize("Enter the length of the second side of the triangle: ") { + Ok(n) => n, + Err(e) => { + eprintln!("Error: {}", e); + exit(1); + } + }; + let result = next_edge(side1, side2); + println!( + "The maximum range of the triangle's third edge is {}", + result + ); +} diff --git a/Week-07/Day-44_Maximum-Edge-Of-A-Triangle/day44/tests/examples.rs b/Week-07/Day-44_Maximum-Edge-Of-A-Triangle/day44/tests/examples.rs new file mode 100644 index 0000000..6acf302 --- /dev/null +++ b/Week-07/Day-44_Maximum-Edge-Of-A-Triangle/day44/tests/examples.rs @@ -0,0 +1,19 @@ +#[cfg(test)] +mod tests { + use day44::next_edge; + + #[test] + fn example1() { + assert_eq!(next_edge(8, 10), 17); + } + + #[test] + fn example2() { + assert_eq!(next_edge(5, 7), 11); + } + + #[test] + fn example3() { + assert_eq!(next_edge(9, 2), 10); + } +}