Wrote program for Day 44
This commit is contained in:
parent
78c4cd6528
commit
4905178181
@ -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: |
|
||||
|
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "day44"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,3 @@
|
||||
pub fn next_edge(side1: usize, side2: usize) -> usize {
|
||||
side1 + side2 - 1
|
||||
}
|
30
Week-07/Day-44_Maximum-Edge-Of-A-Triangle/day44/src/main.rs
Normal file
30
Week-07/Day-44_Maximum-Edge-Of-A-Triangle/day44/src/main.rs
Normal file
@ -0,0 +1,30 @@
|
||||
use std::process::exit;
|
||||
|
||||
use day44::next_edge;
|
||||
|
||||
pub fn read_usize() -> Result<usize, std::num::ParseIntError> {
|
||||
let mut input = String::new();
|
||||
std::io::stdin()
|
||||
.read_line(&mut input)
|
||||
.expect("Failed to read input");
|
||||
input.trim().parse()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let side1 = match read_usize() {
|
||||
Ok(n) => n,
|
||||
Err(e) => {
|
||||
eprintln!("Error: {}", e);
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
let side2 = match read_usize() {
|
||||
Ok(n) => n,
|
||||
Err(e) => {
|
||||
eprintln!("Error: {}", e);
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
let result = next_edge(side1, side2);
|
||||
println!("The maximum range of a triangle's third edge is {}", result);
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user