Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nerdsniped into doing piglatin
use std::io;
fn main() {
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("Failed to read line");
println!("{}", piglatinize(input.trim()));
}
fn piglatinize(s: &str) -> String {
if s.is_empty() {
return String::new();
}
match first_vowel_location(s) {
None => s.to_string() + "-hay",
Some(index) => s[index..].to_string() + &s[..index] + "-ay",
}
}
fn first_vowel_location(s: &str) -> Option<usize> {
let vowels: &[_] = &['a', 'i', 'u', 'e', 'o'];
s.find(vowels)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment