Wrote program for Day 46

This commit is contained in:
Mariano Riefolo 2024-09-09 09:09:36 +02:00
parent 00146175f8
commit ee7740c90d
5 changed files with 52 additions and 1 deletions

View File

@ -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: |

View File

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

View File

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

View File

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

View File

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