Skip to content

Instantly share code, notes, and snippets.

@cristianrasch
Created March 12, 2019 11:46
Show Gist options
  • Save cristianrasch/fa4bf5b40d86003058abef5f92bbeb7d to your computer and use it in GitHub Desktop.
Save cristianrasch/fa4bf5b40d86003058abef5f92bbeb7d to your computer and use it in GitHub Desktop.
use std::iter::{once, repeat};
fn main() {
let fizzes = repeat("").take(2).chain(once("fizz")).cycle();
let buzzes = repeat("").take(4).chain(once("buzz")).cycle();
let fizzes_buzzes = fizzes.zip(buzzes);
let fizz_buzz = (1..=100).zip(fizzes_buzzes).map(|tuple| match tuple {
(i, ("", "")) => i.to_string(),
(_, (fizz, buzz)) => format!("{}{}", fizz, buzz),
});
for line in fizz_buzz {
println!("{}", line);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment