Skip to content

Instantly share code, notes, and snippets.

@abreslav
Forked from ianbattersby/gist:5201036
Last active December 15, 2015 04:39
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 abreslav/5203175 to your computer and use it in GitHub Desktop.
Save abreslav/5203175 to your computer and use it in GitHub Desktop.
fun Int.divides(d: Int) = this % d == 0
fun fizzbuzz(n: Int) = when {
n divides 15 -> "fizzbuzz"
n divides 3 -> "fizz"
n divides 5 -> "buzz"
else -> "$n"
}
fun result(max: Int) = (0..max) map { n -> fizzbuzz(n) }
// Optionally, to print it out
fun main(args: Array<String>) {
println(result(100))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment