Skip to content

Instantly share code, notes, and snippets.

@skht777
Last active January 8, 2017 07:33
Show Gist options
  • Select an option

  • Save skht777/5664297a361bfd3b3cc36e12efd027c3 to your computer and use it in GitHub Desktop.

Select an option

Save skht777/5664297a361bfd3b3cc36e12efd027c3 to your computer and use it in GitHub Desktop.
ScalaのStreamで書いたFizzBuzz
object FizzBuzzStream {
private def calc(fizzbuzz: (Int, Int), i: Int):Stream[String] = {
val s = (i % fizzbuzz._1, i % fizzbuzz._2) match {
case (0, 0) => "FizzBuzz"
case (0, _) => "Fizz"
case (_, 0) => "Buzz"
case _ => i.toString
}
s #:: this.calc(fizzbuzz, i + 1)
}
def apply(fizzbuzz: (Int, Int)): Stream[String] = this.calc(fizzbuzz, 1)
}
object FizzBuzz extends App {
println(FizzBuzzStream((3, 5)) take 100 mkString " ")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment