Skip to content

Instantly share code, notes, and snippets.

@UberMouse
Created June 5, 2013 05:35
Show Gist options
  • Save UberMouse/5711813 to your computer and use it in GitHub Desktop.
Save UberMouse/5711813 to your computer and use it in GitHub Desktop.
First FizzBuzz solution
/**
* Created by IntelliJ IDEA.
* User: UberMouse
* Date: 10/26/11
* Time: 12:50 PM
*/
object fizzbuzz {
def main(args: Array[String]) {
val source = scala.io.Source.fromFile(args(0))
val lines = source.getLines().filter(_.length > 0)
for (l <- lines) {
val ints = l.split(" ").map(str => Integer.parseInt(str))
println(fizzbuzzstr(ints(2), ints(0), ints(1)))
}
}
def fizzbuzzstr(amount: Int, fizz: Int, buzz: Int) = {
(1 to amount).mkString(",").split(",").map(str => {
val num = Integer.parseInt(str);
if (num % fizz == 0 && num % buzz == 0) "FB"
else if (num % buzz == 0) "B"
else if (num % fizz == 0) "F"
else str
}).mkString(" ")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment