Last active
August 29, 2015 14:01
-
-
Save joebalancio/1b9ec06dd2f6a532b4af to your computer and use it in GitHub Desktop.
Fizz Buzz in Scala
This file contains hidden or 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
val rules = Map(3 -> "fizz", 5 -> "buzz") | |
for { | |
i <- 1 to 100 | |
val out = rules.map { case (m, w) => if (i % m == 0) Option(w) else None }.flatten.reduceOption(_ + _).getOrElse(i) | |
} println(out) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment