Skip to content

Instantly share code, notes, and snippets.

@skoop
Created November 25, 2017 10:26
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 skoop/216ac805148b917d55a1850b46747d75 to your computer and use it in GitHub Desktop.
Save skoop/216ac805148b917d55a1850b46747d75 to your computer and use it in GitHub Desktop.
Second attempt at doing the 99 bottles code kata with Kotlin
package org.domcode.kata
fun main(args: Array<String>) {
for (i in 0..99) {
val bottleAmount: Int = getAmount(i)
val oneLess: Int = subtractOne(bottleAmount)
when {
bottleAmount > 1 -> println("$bottleAmount bottles of beer on the wall, $bottleAmount bottles of beer.")
bottleAmount == 1 -> println("$bottleAmount bottle of beer on the wall, $bottleAmount bottle of beer.")
else -> println("0 bottles of beer on the wall, 0 bottles of beer.")
}
when {
oneLess == 1 -> println("Take one down, pass it around, $oneLess bottle of beer on the wall.")
oneLess == -1 -> println("Go to the store, buy some more, 99 bottles of beer on the wall.")
else -> println("Take one down, pass it around, $oneLess bottles of beer on the wall.")
}
println()
}
}
fun subtractOne(number: Int): Int {
return number - 1
}
fun getAmount(number: Int): Int {
return 99 - number
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment