daily pastebin goal
25%
SHARE
TWEET

Untitled

a guest May 16th, 2018 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn main() {
  2.     println!("{}", raindrops(3));
  3. }
  4.  
  5. pub fn raindrops(n: usize) -> String {
  6.     let sound = (1..=n)
  7.         .filter(|x| n % x == 0)
  8.         .map(|x| match x {
  9.             7 => "Plong",
  10.             5 => "Plang",
  11.             3 => "Pling",
  12.             _ => "",
  13.         })
  14.         .collect::<Vec<&str>>()
  15.         .join("");
  16.     //if sound.is_empty() {
  17.     //    n.to_string()
  18.     //} else {
  19.     //    sound
  20.     match sound.is_empty() {
  21.         true => n.to_string(),
  22.         false => sound,
  23.     }
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top