Last active
March 19, 2020 21:06
-
-
Save abdolence/eb3038c400ece788fb77132a36757393 to your computer and use it in GitHub Desktop.
medium-fizzbuss-straightforward-algo
This file contains 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 characters
def basicFizzbuzzRules( x: Int ): String = { | |
( x % 3, x % 5 ) match { | |
case ( 0, 0 ) => "FizzBuzz" | |
case ( 0, _ ) => "Fizz" | |
case ( _, 0 ) => "Buzz" | |
case _ => x.toString | |
} | |
} | |
def fizzbuzz( n: Int )( rules: Int => String ): LazyList[String] = { | |
LazyList | |
.range( 0, n ) | |
.map( rules ) | |
} | |
// Let's print the first N | |
val N = 100 | |
fizzbuzz( N )( basicFizzbuzzRules ).foreach( println ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment