Guest User

Untitled

a guest
May 16th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  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. }
Add Comment
Please, Sign In to add comment