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.

Revisions

  1. skht777 revised this gist Jan 8, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions FizzBuzz.scala
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,16 @@
    object FizzBuzzStream {
    def apply(fizz: Int = 3, buzz: Int = 5): Stream[String] = {
    def stream(fizz: Int, buzz: Int, i: Int): Stream[String] = {
    def stream(i: Int): Stream[String] = {
    val s = (i % fizz, i % buzz) match {
    case (0, 0) => "FizzBuzz"
    case (0, _) => "Fizz"
    case (_, 0) => "Buzz"
    case _ => i.toString
    }
    s #:: stream(fizz, buzz, i + 1)
    s #:: stream(i + 1)
    }

    stream(fizz, buzz, 1)
    stream(1)
    }
    }

  2. skht777 revised this gist Jan 8, 2017. 1 changed file with 12 additions and 9 deletions.
    21 changes: 12 additions & 9 deletions FizzBuzz.scala
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,19 @@
    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
    def apply(fizz: Int = 3, buzz: Int = 5): Stream[String] = {
    def stream(fizz: Int, buzz: Int, i: Int): Stream[String] = {
    val s = (i % fizz, i % buzz) match {
    case (0, 0) => "FizzBuzz"
    case (0, _) => "Fizz"
    case (_, 0) => "Buzz"
    case _ => i.toString
    }
    s #:: stream(fizz, buzz, i + 1)
    }
    s #:: this.calc(fizzbuzz, i + 1)

    stream(fizz, buzz, 1)
    }
    def apply(fizzbuzz: (Int, Int)): Stream[String] = this.calc(fizzbuzz, 1)
    }

    object FizzBuzz extends App {
    println(FizzBuzzStream((3, 5)) take 100 mkString " ")
    println(FizzBuzzStream() take 100 mkString " ")
    }
  3. skht777 created this gist Jan 7, 2017.
    16 changes: 16 additions & 0 deletions FizzBuzz.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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 " ")
    }