Created
September 11, 2018 09:13
-
-
Save Serchinastico/34c1e3658bc9230e513ba72ae64b9396 to your computer and use it in GitHub Desktop.
Tail recursive FizzBuzz in kotlin
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
tailrec fun fizzbuzz(vararg args: Int) { | |
if (args.isEmpty()) return | |
val arg = args[0] | |
when { | |
arg % 15 == 0 -> print("FizzBuzz") | |
arg % 3 == 0 -> print("Fizz") | |
arg % 5 == 0 -> print("Buzz") | |
} | |
fizzbuzz(*args.drop(1).toIntArray()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment