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

Date:06/22/12
Author:Franck Rasolo
URL:http://www.linkedin.com/in/franckrasolo
Comments:0
Info:http://www.jetbrains.com/kotlin
Score: (3.41 in 73 votes)
fun main(args: Array<String>) = 99 downto 0 map { verse(it) } forEach { println(it) }

fun verse(n: Int) = when (n) {
  0 -> """N${n.bottles().substring(1)} of beer on the wall, ${n.bottles()} of beer.
Go to the store and buy some more, ${99.bottles()} of beer on the wall."""

  else -> """${n.bottles()} of beer on the wall, ${n.bottles()} of beer.
Take one down and pass it around, ${(n - 1).bottles()} of beer on the wall.
"""
}

fun Int.bottles() = when (this) { 0 -> "no more bottles" 1 -> "1 bottle" else -> "$this bottles" }

Download Source | Write Comment

Alternative Versions

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: