Skip to content

Instantly share code, notes, and snippets.

@UberMouse
Created June 5, 2013 05:57
Show Gist options
  • Save UberMouse/5711878 to your computer and use it in GitHub Desktop.
Save UberMouse/5711878 to your computer and use it in GitHub Desktop.
Slightly better version of FizzBuzz
object Main extends App {
val source = scala.io.Source.fromFile(args(0))
source.getLines
.filter(_.length > 0)
.map(_.split(" ").map(_.toInt))
.map(x => fizz(x(0), x(1), x(2)))
.foreach(println)
def fizz(a:Int, b:Int, n:Int) = {
def buzz(check:Int, fizz:Int, buzz:Int) = {
val f = check % fizz == 0
val b = check % buzz == 0
if(f && b) "FB"
else if(f) "F"
else if(b) "B"
else check.toString
}
1 to n map(x => buzz(x, a, b))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment