From ee7740c90d5fd8719514fdeb95368e729a4d3dfd Mon Sep 17 00:00:00 2001 From: Mariano Riefolo Date: Mon, 9 Sep 2024 09:09:36 +0200 Subject: [PATCH] Wrote program for Day 46 --- README.md | 2 +- .../day46/Cargo.toml | 6 +++++ .../day46/src/lib.rs | 9 ++++++++ .../day46/src/main.rs | 14 ++++++++++++ .../day46/tests/examples.rs | 22 +++++++++++++++++++ 5 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 Week-07/Day-46_Hot-Pics-Of-Danny-Devito/day46/Cargo.toml create mode 100644 Week-07/Day-46_Hot-Pics-Of-Danny-Devito/day46/src/lib.rs create mode 100644 Week-07/Day-46_Hot-Pics-Of-Danny-Devito/day46/src/main.rs create mode 100644 Week-07/Day-46_Hot-Pics-Of-Danny-Devito/day46/tests/examples.rs diff --git a/README.md b/README.md index dd6a5cc..6975f74 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ We encourage you to share your progress and ask questions in the Discussions sec | 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_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_check_mark: | -| 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_check_mark: | | Day #47 | [Zip It](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-07/Day-47_Zip-It) | :white_large_square: | | Day #48 | [Christmas Tree](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-07/Day-48_Christmas-Tree) | :white_large_square: | | Day #49 | [Swimming Pool](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-07/Day-49_Swimming-Pool) | :white_large_square: | diff --git a/Week-07/Day-46_Hot-Pics-Of-Danny-Devito/day46/Cargo.toml b/Week-07/Day-46_Hot-Pics-Of-Danny-Devito/day46/Cargo.toml new file mode 100644 index 0000000..5654f91 --- /dev/null +++ b/Week-07/Day-46_Hot-Pics-Of-Danny-Devito/day46/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "day46" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/Week-07/Day-46_Hot-Pics-Of-Danny-Devito/day46/src/lib.rs b/Week-07/Day-46_Hot-Pics-Of-Danny-Devito/day46/src/lib.rs new file mode 100644 index 0000000..d11f305 --- /dev/null +++ b/Week-07/Day-46_Hot-Pics-Of-Danny-Devito/day46/src/lib.rs @@ -0,0 +1,9 @@ +pub fn prevent_distractions(video_title: &str) -> String { + let words = ["anime", "meme", "vines", "roasts", "Danny DeVito"]; + for word in words { + if video_title.contains(word) { + return "NO!".to_string(); + } + } + "Safe watching!".to_string() +} diff --git a/Week-07/Day-46_Hot-Pics-Of-Danny-Devito/day46/src/main.rs b/Week-07/Day-46_Hot-Pics-Of-Danny-Devito/day46/src/main.rs new file mode 100644 index 0000000..5d75562 --- /dev/null +++ b/Week-07/Day-46_Hot-Pics-Of-Danny-Devito/day46/src/main.rs @@ -0,0 +1,14 @@ +use std::io::{self, Write}; + +use day46::prevent_distractions; + +fn main() { + print!("Insert video title: "); + io::stdout().flush().unwrap(); + let mut buffer = String::new(); + io::stdin() + .read_line(&mut buffer) + .expect("Failed to read line"); + let result = prevent_distractions(buffer.trim()); + println!("{}", result); +} diff --git a/Week-07/Day-46_Hot-Pics-Of-Danny-Devito/day46/tests/examples.rs b/Week-07/Day-46_Hot-Pics-Of-Danny-Devito/day46/tests/examples.rs new file mode 100644 index 0000000..3b69e9e --- /dev/null +++ b/Week-07/Day-46_Hot-Pics-Of-Danny-Devito/day46/tests/examples.rs @@ -0,0 +1,22 @@ +#[cfg(test)] +mod examples { + use day46::prevent_distractions; + + #[test] + fn example1() { + assert_eq!(prevent_distractions("vines that butter my eggroll"), "NO!"); + } + + #[test] + fn example2() { + assert_eq!(prevent_distractions("Hot pictures of Danny DeVito"), "NO!"); + } + + #[test] + fn example3() { + assert_eq!( + prevent_distractions("How to ace BC Calculus in 5 Easy Steps"), + "Safe watching!" + ); + } +}