Guest User

Untitled

a guest
May 25th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. fun main(args: Array<String>) {
  2. (1..50)
  3. .map(::toFizzBuzz)
  4. .forEach(::println)
  5. }
  6.  
  7. private fun toFizzBuzz(i: Int) =
  8. when {
  9. i.divisibleBy(15) -> "Fizz Buzz"
  10. i.divisibleBy(3) -> "Fizz"
  11. i.divisibleBy(5) -> "Buzz"
  12. else -> i.toString()
  13. }
  14.  
  15. private fun Int.divisibleBy(i: Int) = this % i == 0
Add Comment
Please, Sign In to add comment