Created
March 12, 2019 11:46
-
-
Save cristianrasch/fa4bf5b40d86003058abef5f92bbeb7d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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