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 R

(Recursive Approach)

Date:01/04/06
Author:Roland
URL:n/a
Comments:0
Info:http://www.r-project.org
Score: (3.00 in 57 votes)
### "Recursive Bottles"
### 04 Jan 2006, Roland Rau, roland.rau@gmail.com
beersong <- function(n) {
  if (n==1) {
    cat("\n",n," bottle of beer on the wall, ",n,
        " bottles of beer.\nTake one down and pass it around,",
        " no more bottles of beer on the wall.\n", sep="")
    cat("\nNo more bottles of beer on the wall, no more bottles of beer.\n",
        "Go to the store and buy some more, 99 bottles of beer on the wall.\n", sep="")
  } else {
    cat("\n",n," bottles of beer on the wall, ",n,
        " bottles of beer.\nTake one down and pass it around, ",
        n-1, " more bottles of beer on the wall.\n", sep="")
    return(beersong(n-1))
  }
}

beersong(99)

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
Vectorized and makes correct lyricsGiovanni Millo10/05/051
Dataframe approachDavid Dailey05/03/080

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: