Created
April 2, 2012 16:24
-
-
Save ryanoneill/2284759 to your computer and use it in GitHub Desktop.
FizzBuzz in Scala
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
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)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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