Skip to content

Instantly share code, notes, and snippets.

@kjellski
Forked from gigamonkey/FizzBuzz.scala
Created May 15, 2013 06:51
Show Gist options
  • Save kjellski/5582080 to your computer and use it in GitHub Desktop.
Save kjellski/5582080 to your computer and use it in GitHub Desktop.
object FizzBuzz extends App {
val nones = Stream.continually(None)
val fizzes: Stream[Option[String]] = nones.take(2) ++ Some("Fizz") #:: fizzes
val buzzes: Stream[Option[String]] = nones.take(4) ++ Some("Buzz") #:: buzzes
for (((fizz, buzz), n) <- fizzes zip buzzes zip (1 to 100)) {
println(fizz.map(_ + buzz.getOrElse("")).orElse(buzz).getOrElse(n))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment