Skip to content

Instantly share code, notes, and snippets.

@skoop
Created November 25, 2017 10:25
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/7e6ba4169ea3ee4951c494e02377daa3 to your computer and use it in GitHub Desktop.
Save skoop/7e6ba4169ea3ee4951c494e02377daa3 to your computer and use it in GitHub Desktop.
My first attempt at doing the 99 bottles code kata in 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)
if (bottleAmount > 1) {
println("$bottleAmount bottles of beer on the wall, $bottleAmount bottles of beer.")
if (oneLess == 1) {
println("Take one down, pass it around, $oneLess bottle of beer on the wall.")
} else {
println("Take one down, pass it around, $oneLess bottles of beer on the wall.")
}
} else {
if (bottleAmount == 1) {
println("$bottleAmount bottle of beer on the wall, $bottleAmount bottle of beer.")
println("Take one down, pass it around, $oneLess bottles of beer on the wall.")
} else {
println("0 bottles of beer on the wall, 0 bottles of beer.")
println("Go to the store, buy some more, 99 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