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
Version | Author | Date | Comments | Rate |
---|---|---|---|---|
Vectorized and makes correct lyrics | Giovanni Millo | 10/05/05 | 1 | |
Dataframe approach | David Dailey | 05/03/08 | 0 |
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