Last active
December 23, 2015 04:39
-
-
Save mogproject/6581465 to your computer and use it in GitHub Desktop.
FizzBuzz in Scala
This file contains hidden or 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 { | |
private val divs = List((3, "Fizz"), (5, "Buzz")) | |
def fizzBuzz(n: Int): String = { | |
val ret = (divs map {case (i, s) => if (n % i == 0) s else ""}).mkString | |
if (ret.isEmpty) n.toString else ret | |
} | |
def main(args: Array[String]) { | |
def printAll(n: Int) { (1 to n) foreach {n => println(fizzBuzz(n))} } | |
// printAll(args(0).toInt) | |
printAll(100) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment