Anonymous user
99 bottles of beer: Difference between revisions
→{{header|R}}: Made subsections for the varying implementations
No edit summary |
(→{{header|R}}: Made subsections for the varying implementations) |
||
Line 3,844:
=={{header|R}}==
===Simple looping solution===
<lang R>#only one line!▼
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="")▼
#alternative▼
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>▼
<lang R>#a naive function to sing for N bottles of beer...
Line 3,867 ⟶ 3,861:
}
song(99)#play the song by calling the function</lang>▼
===Vector solutions===
▲song(99)#play the song by calling the function</lang>
▲<lang R>#only one line!
▲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="")
▲#alternative
▲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}}==
|