Skip to content

Instantly share code, notes, and snippets.

@abdolence
Last active March 19, 2020 21:06
Show Gist options
  • Save abdolence/eb3038c400ece788fb77132a36757393 to your computer and use it in GitHub Desktop.
Save abdolence/eb3038c400ece788fb77132a36757393 to your computer and use it in GitHub Desktop.
medium-fizzbuss-straightforward-algo
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