Skip to content

Instantly share code, notes, and snippets.

@ckirkendall
Forked from bkyrlach/Program.scala
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckirkendall/27c6e860fc038b623c9e to your computer and use it in GitHub Desktop.
Save ckirkendall/27c6e860fc038b623c9e to your computer and use it in GitHub Desktop.
// After reading the trials and tribulations here
// http://www.learningclojure.com/2014/05/fizz-buzz-interview-question.html?utm_source=dlvr.it&utm_medium=twitter
// I decided to see how easy this is using sum types.
// Anser: Pretty easy. :D
object Program {
def numbers(n: Int): Stream[Int] = Stream.cons(n, numbers(n + 1))
def main(args: Array[String]): Unit = {
numbers(1).take(100)
.map(n => if(n % 15 == 0) "fizzbuzz"
else if (n % 5 == 0) "buzz"
else if (n % 3 == 0) "fizz"
else n.toString()).toList.foreach(println)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment