-
-
Save ckirkendall/27c6e860fc038b623c9e to your computer and use it in GitHub Desktop.
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
// 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