Language Kotlin
(More concise than JetBrains' solution)
| Date: | 01/16/12 |
| Author: | Franck Rasolo |
| URL: | http://www.linkedin.com/in/franckrasolo |
| Comments: | 0 |
| Info: | www.jetbrains.com/kotlin |
| Score: |
fun main(args : Array<String>) {
for (n in (-(0..99)).iterator()) System.out?.println(verse(n))
}
fun verse(n: Int) = when (n) {
0 -> "N${n.bottles().substring(1)} on the wall, ${n.bottles()}.\n" +
"Go to the store and buy some more, ${99.bottles()}"
else -> "${n.bottles()} on the wall, ${n.bottles()}.\n" +
"Take one down and pass it around, ${(n - 1).bottles()}"
} + " on the wall.\n"
fun Int.bottles() = when (int) {
0 -> "no more bottles"
1 -> "1 bottle"
else -> "${int} bottles"
} + " of beer"
Download Source | Write Comment
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments