Created
June 5, 2013 05:57
-
-
Save UberMouse/5711878 to your computer and use it in GitHub Desktop.
Slightly better version of FizzBuzz
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 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