Skip to content

Instantly share code, notes, and snippets.

@ryanoneill
Created April 2, 2012 16:24
Show Gist options
  • Save ryanoneill/2284759 to your computer and use it in GitHub Desktop.
Save ryanoneill/2284759 to your computer and use it in GitHub Desktop.
FizzBuzz in Scala
object FizzBuzz {
def main(args: Array[String]) {
1 to 100 foreach printlnEncoded
}
def encode(value: Int) =
value match {
case x if (x % 15 == 0) => "FizzBuzz"
case y if (y % 5 == 0) => "Buzz"
case z if (z % 3 == 0) => "Fizz"
case _ => value
}
def printlnEncoded(value: Int) =
println(encode(value))
}
@ryanoneill
Copy link
Author

My version of the infamous FizzBuzz program mentioned by Jeff Atwood in Why Can't Programmers.. Program?
http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment