Skip to content

Instantly share code, notes, and snippets.

@chokkoyamada
Created June 7, 2013 11:46
Show Gist options
  • Save chokkoyamada/5728717 to your computer and use it in GitHub Desktop.
Save chokkoyamada/5728717 to your computer and use it in GitHub Desktop.
def fizzBuzz(n:Int):String=n match {
case n if n % 15 == 0 => "fizzbuzz"
case n if n % 3 == 0 => "fizz"
case n if n % 5 == 0 => "buzz"
case _ => n.toString()
}
assert(fizzBuzz(3) == "fizz")
assert(fizzBuzz(4) == "4")
assert(fizzBuzz(15) == "fizzbuzz")
assert(fizzBuzz(30) == "fizzbuzz")
1 to 100 foreach(x => println(fizzBuzz(x)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment