Skip to content

Instantly share code, notes, and snippets.

@samklr
Forked from gigamonkey/FizzBuzz.scala
Created July 28, 2013 14:23
Show Gist options
  • Select an option

  • Save samklr/6098769 to your computer and use it in GitHub Desktop.

Select an option

Save samklr/6098769 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