Skip to content

Instantly share code, notes, and snippets.

@lazyval
Created November 20, 2011 20:51
Show Gist options
  • Save lazyval/1380892 to your computer and use it in GitHub Desktop.
Save lazyval/1380892 to your computer and use it in GitHub Desktop.
Fizzbuzz in scala
object FizzBuzz extends App {
def fizzbuzz(line: String) = {
val Array(a,b,n) = line.split(" ").map(_.toInt)
(1 to n).map(x =>
(x%a,x%b) match {
case (0,0) => "FB"
case (0,_) => "F"
case (_,0) => "B"
case _ => x
}
)
}
val source = scala.io.Source.fromFile(args(0))
val res = source.getLines.map(fizzbuzz(_).mkString(" "))
res.foreach(println(_))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment