Created
November 25, 2017 10:25
-
-
Save skoop/7e6ba4169ea3ee4951c494e02377daa3 to your computer and use it in GitHub Desktop.
My first attempt at doing the 99 bottles code kata 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
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