Last active
January 15, 2024 14:49
-
-
Save jakobjpeters/c58e87df98008baebcbcac55a569c84b to your computer and use it in GitHub Desktop.
Fizz Buzz with lazy iterators
This file contains 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
#= | |
Adapted from: | |
Kevlin Henney | |
https://www.youtube.com/watch?v=nrVIlhtoE3Y | |
=# | |
julia> fizz_buzz(words...) = Iterators.map(max, | |
Iterators.map(string, Iterators.countfrom()), | |
Iterators.map(*, Iterators.map( | |
((s, n),) -> Iterators.cycle(push!(repeat([""], n - 1), s)), | |
words)...) | |
); | |
julia> foreach(println, Iterators.take(fizz_buzz("Fizz" => 3, "Buzz" => 5), 15)) | |
1 | |
2 | |
Fizz | |
4 | |
Buzz | |
Fizz | |
7 | |
8 | |
Fizz | |
Buzz | |
11 | |
Fizz | |
13 | |
14 | |
FizzBuzz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment