|
|
Line 3,844: |
Line 3,844: |
|
|
|
|
|
=={{header|R}}== |
|
=={{header|R}}== |
|
|
===Simple looping solution=== |
⚫ |
|
|
⚫ |
cat(paste(99:1,ifelse((99:1)!=1," bottles"," bottle")," of beer on the wall\n",99:1,ifelse((99:1)!=1," bottles"," bottle")," of beer\n","Take one down, pass it around\n",98:0,ifelse((98:0)!=1," bottles"," bottle")," of beer on the wall\n\n",sep=""),sep="") |
|
|
|
|
⚫ |
|
|
⚫ |
cat(paste(lapply(99:1,function(i){paste(paste(rep(paste(i,' bottle',if(i!=1)'s',' of beer',sep=''),2),collapse =' on the wall\n'),'Take one down, pass it around',paste(i-1,' bottle',if(i!=2)'s',' of beer on the wall',sep=''), sep='\n')}),collapse='\n\n'))</lang> |
|
|
|
|
|
Easier to follow: |
|
|
|
|
|
|
<lang R>#a naive function to sing for N bottles of beer... |
|
<lang R>#a naive function to sing for N bottles of beer... |
Line 3,867: |
Line 3,861: |
|
} |
|
} |
|
|
|
|
|
⚫ |
song(99)#play the song by calling the function</lang> |
|
|
|
|
|
|
===Vector solutions=== |
⚫ |
song(99)#play the song by calling the function</lang> |
|
|
⚫ |
|
|
⚫ |
cat(paste(99:1,ifelse((99:1)!=1," bottles"," bottle")," of beer on the wall\n",99:1,ifelse((99:1)!=1," bottles"," bottle")," of beer\n","Take one down, pass it around\n",98:0,ifelse((98:0)!=1," bottles"," bottle")," of beer on the wall\n\n",sep=""),sep="") |
|
|
|
|
⚫ |
|
|
⚫ |
cat(paste(lapply(99:1,function(i){paste(paste(rep(paste(i,' bottle',if(i!=1)'s',' of beer',sep=''),2),collapse =' on the wall\n'),'Take one down, pass it around',paste(i-1,' bottle',if(i!=2)'s',' of beer on the wall',sep=''), sep='\n')}),collapse='\n\n'))</lang> |
|
|
|
|
|
=={{header|REALbasic}}== |
|
=={{header|REALbasic}}== |