Wrote program for Day 44

This commit is contained in:
Mariano Riefolo 2024-09-07 09:53:21 +02:00
parent 78c4cd6528
commit 617d141847
5 changed files with 67 additions and 1 deletions

View File

@ -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 #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 #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 #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 #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 #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: | | Day #47 | [Zip It](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-07/Day-47_Zip-It) | :white_large_square: |

View File

@ -0,0 +1,6 @@
[package]
name = "day44"
version = "0.1.0"
edition = "2021"
[dependencies]

View File

@ -0,0 +1,3 @@
pub fn next_edge(side1: usize, side2: usize) -> usize {
side1 + side2 - 1
}

View File

@ -0,0 +1,38 @@
use std::{
io::{self, Write},
process::exit,
};
use day44::next_edge;
pub fn read_usize(request: &str) -> Result<usize, std::num::ParseIntError> {
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
);
}

View File

@ -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);
}
}