Created
June 21, 2019 03:21
-
-
Save josephsdavid/4d21e54fef60501584ee296f954e8d14 to your computer and use it in GitHub Desktop.
99 bottles of beer in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
beersong <- function(n=99) { | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment