Last active
January 8, 2017 07:33
-
-
Save skht777/5664297a361bfd3b3cc36e12efd027c3 to your computer and use it in GitHub Desktop.
Revisions
-
skht777 revised this gist
Jan 8, 2017 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal 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(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(i + 1) } stream(1) } } -
skht777 revised this gist
Jan 8, 2017 . 1 changed file with 12 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,19 @@ object FizzBuzzStream { 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) } stream(fizz, buzz, 1) } } object FizzBuzz extends App { println(FizzBuzzStream() take 100 mkString " ") } -
skht777 created this gist
Jan 7, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal 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 " ") }