99 Bottles of Beer
-
In JavaScript I need the shortest possible code to generate the 99 bottles of beer on the wall song lyrics into a string (using "\n" as the line separator). The problem is making it grammatically correct while still keeping the code compact. For a refresher: 99 bottles of beer on the wall, 99 bottles of beer. Take one down and pass it around, 98 bottles of beer on the wall. 98 bottles of beer on the wall, 98 bottles of beer. Take one down and pass it around, 97 bottles of beer on the wall. 97 bottles of beer on the wall, 97 bottles of beer. Take one down and pass it around, 96 bottles of beer on the wall. ... 2 bottles of beer on the wall, 2 bottles of beer. Take one down and pass it around, 1 bottle of beer on the wall. 1 bottle of beer on the wall, 1 bottle of beer. Take one down and pass it around, no more bottles of beer on the wall. I'm searching for the cleverest, most compact approach. Any ideas?
-
In JavaScript I need the shortest possible code to generate the 99 bottles of beer on the wall song lyrics into a string (using "\n" as the line separator). The problem is making it grammatically correct while still keeping the code compact. For a refresher: 99 bottles of beer on the wall, 99 bottles of beer. Take one down and pass it around, 98 bottles of beer on the wall. 98 bottles of beer on the wall, 98 bottles of beer. Take one down and pass it around, 97 bottles of beer on the wall. 97 bottles of beer on the wall, 97 bottles of beer. Take one down and pass it around, 96 bottles of beer on the wall. ... 2 bottles of beer on the wall, 2 bottles of beer. Take one down and pass it around, 1 bottle of beer on the wall. 1 bottle of beer on the wall, 1 bottle of beer. Take one down and pass it around, no more bottles of beer on the wall. I'm searching for the cleverest, most compact approach. Any ideas?
It's your homework; you do it. Or maybe you could search for a website with that problem already written in many languages...
-
It's your homework; you do it. Or maybe you could search for a website with that problem already written in many languages...
-
In JavaScript I need the shortest possible code to generate the 99 bottles of beer on the wall song lyrics into a string (using "\n" as the line separator). The problem is making it grammatically correct while still keeping the code compact. For a refresher: 99 bottles of beer on the wall, 99 bottles of beer. Take one down and pass it around, 98 bottles of beer on the wall. 98 bottles of beer on the wall, 98 bottles of beer. Take one down and pass it around, 97 bottles of beer on the wall. 97 bottles of beer on the wall, 97 bottles of beer. Take one down and pass it around, 96 bottles of beer on the wall. ... 2 bottles of beer on the wall, 2 bottles of beer. Take one down and pass it around, 1 bottle of beer on the wall. 1 bottle of beer on the wall, 1 bottle of beer. Take one down and pass it around, no more bottles of beer on the wall. I'm searching for the cleverest, most compact approach. Any ideas?
Here's the one I made. 194 characters long. This is my first time code golfing, but I think i'm getting the hang of it. :suss:
for(var $=b=c=d='',_=99,a=' on the wall.';b=' bottle'+(~(_-2)?'s':d)+' of beer',_>~0;c=_--&&'\n\n') 99-_&&($+='.\nTake one down and pass it around, '+(_||'no more')+b+a),$+=_?c+_+b+a+', '+_+b:d;
console.log($);
-
Here's the one I made. 194 characters long. This is my first time code golfing, but I think i'm getting the hang of it. :suss:
for(var $=b=c=d='',_=99,a=' on the wall.';b=' bottle'+(~(_-2)?'s':d)+' of beer',_>~0;c=_--&&'\n\n') 99-_&&($+='.\nTake one down and pass it around, '+(_||'no more')+b+a),$+=_?c+_+b+a+', '+_+b:d;
console.log($);
-
PIEBALDconsult wrote:
Its a cool website but the JavaScript one was pretty disappointing, its badly written, then encrypted with an escape sequence to hide the actual code.