Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

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: (3.32 in 25 votes)
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

Alternative Versions

VersionAuthorDateCommentsRate
1Franck Rasolo06/22/120

Comments

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!

Name:

eMail:

URL:

Security Code:
  
Comment: