Wrote program for Day 2

This commit is contained in:
Mariano Riefolo 2024-07-27 14:59:53 +02:00
parent 4f0b2678c2
commit 042f3bf7fa
2 changed files with 35 additions and 0 deletions

View File

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

View File

@ -0,0 +1,29 @@
use std::io::{self, Write};
fn find_nemo(word: &str) -> Option<usize> {
for (i, word) in word.split(" ").enumerate() {
if word == "Nemo" {
return Some(i + 1);
}
}
None
}
fn main() {
let mut buffer = String::new();
print!("Insert your words: ");
io::stdout().flush().expect("Failed to flush stdout.");
io::stdin()
.read_line(&mut buffer)
.expect("Error while trying to read from stdin.");
let nemo = find_nemo(&buffer);
match nemo {
Some(x) => println!("I found Nemo at {}!", x),
None => println!("I can't find Nemo :("),
}
}