Skip to content

Instantly share code, notes, and snippets.

@ramn
Created November 25, 2012 16:15
Show Gist options
  • Save ramn/4144203 to your computer and use it in GitHub Desktop.
Save ramn/4144203 to your computer and use it in GitHub Desktop.
FizzBuzz in scala, somewhat functional
object Main {
def main(args: Array[String]) = {
def m3(x: Int) = x % 3 == 0
def m5(x: Int) = x % 5 == 0
val checks = List((m3 _, "Fizz"), (m5 _, "Buzz"))
Stream.from(1) map { n =>
checks filter (_._1(n)) map (_._2) reduceOption (_ + _) getOrElse n
} take 100 foreach println
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment