[WARNING: ONE LINE POST] Code Golf: 99 Bottles (JS: 182 bytes)
h
Zavexeon (1041)

This is one line, but a surprising amount of effort went into this one little line.

For those unfamiliar with Code Golf, the goal is to make a program complete a given task in the smallest amount of bytes.

The challenge I took on was the 99 Bottles song. The program must output this song:

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.
...

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.

Keep in mind plurals.

I actually did this some time ago, and @Kognise and I actually combined our solutions. Unfortunately I realized that solution didn't output the lyrics correctly. So I present to you, my best solution I could create in 182 bytes in JS.

for(i=99;i>0;i--)console.log(`${a=' bottle',b=a+(i>1?'s':''),c=' of beer',d=' on the wall',i+b+c}${d}, ${i+b+c}.\nTake one down and pass it around, ${i>1?i-1:'no more'}${a}s${c+d}.`)

This is code at it's most cursed.

You are viewing a single comment. View All
pyelias (1585)

you can take i-- out of the for loop and change i>1?i-1:'no more' to --i||'no more' for 176 chars

pyelias (1585)

@Zavexeon also you can do b=a+(i>1?'s':'')+(c=' of beer') for 172

pyelias (1585)

@Zavexeon nvm, the pluralization in the second to last line breaks if you do that
its fixed with

for(i=99;i;)console.log((p=_=>l=`${i||'no more'} bottle${i^1?'s':''} of beer`)(a=' on the wall')+a+`, ${l}.\nTake one down and pass it around, ${p(--i)+a}.`)

(157), but thats pretty much a separate solution at this point.

Zavexeon (1041)

@pyelias Smh stop making me feel inferior aaaaa