Other "Hello World" solutions.
pub fn hello() -> &'static str {
"Hello, World!"
}
Other "Leap" solutions.
pub fn is_leap_year(year: u64) -> bool {
return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
}
Other "Nth Prime" solutions.
pub fn nth(n: u32) -> u32 {
unimplemented!("What is the 0-indexed {}th prime number?", n)
}
Other "Raindrops" solutions.
pub fn raindrops(n: u32) -> String {
let rain = [(3, "Pling"), (5, "Plang"), (7, "Plong")]
.into_iter()
.filter(|&(number, _)| n % number == 0)
.map(|&(_, sound)| sound)
.collect::<Vec<&str>>()
.join("");
return if rain.is_empty() { n.to_string() } else { rain };
}
Other "Reverse String" solutions.
pub fn reverse(input: &str) -> String {
input.chars().rev().collect::<String>()
}