# Challenge

Write a program that outputs the lyrics to 99 Bottles of Beer, but instead of "beer", output "fizz" if the number of bottles on the wall is a multiple of 3, "buzz" if it is a multiple of 5, and "fizzbuzz" if it is a multiple of 3 and a multiple of 5. If the number of bottles on the wall is not a multiple of 3 or 5, just output "beer" as usual.

## Lyrics

99 bottles of fizz on the wall, 99 bottles of fizz.
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 fizz on the wall.

96 bottles of fizz on the wall, 96 bottles of fizz.
Take one down and pass it around, 95 bottles of buzz on the wall.

95 bottles of buzz on the wall, 95 bottles of buzz.
Take one down and pass it around, 94 bottles of beer on the wall.

....

3 bottles of fizz on the wall, 3 bottles of fizz.
Take one down and pass it around, 2 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.
Go to the store and buy some more, 99 bottles of fizz on the wall.


This is , so the shortest submission in each language wins.

• I have 95 bottles of fizz. I take one away. Now I have 94 bottles of beer. Logic.
– Okx
May 12, 2017 at 19:10
• Can I have a bottle of fizzbeer? May 12, 2017 at 19:15
• Is there supposed to be a newline after the 3rd bottle? May 12, 2017 at 19:29
• Is a newline required between the two lines? Before Kritixi Lithos's edit there were none and now there are. May 12, 2017 at 19:36
• @Okx Well, beer is fizzy and gives you a buzz... May 12, 2017 at 22:09

# Python 2, 263253 245 bytes

i=99
x=''
while i:x+=', %s on the wall.\n\n%s on the wall, %s.\n'%(('%d bottle%s of %s'%(i,'s'*(i>1),(i%3<1)*'fizz'+(i%5<1)*'buzz'or'beer'),)*3)+'GToa kteo  otnhee  dsotwonr ea nadn dp absusy  isto maer omuonrde'[i>1::2];i-=1
print x[35:]+x[:33]


Try it online!

• This is awesome! Can you explain why interpolating the strings is the shortest option? May 13, 2017 at 2:23
• For example ['ab','cd'][x] can be rewritten as 'acbd'[x::2], just to save some bytes
– Rod
May 13, 2017 at 4:01

# C (GCC), 276 274 bytes

Thanks to Neil for saving two bytes!

#define w" on the wall"
#define c(i)printf("%d bottle%s of %s",i,"s"+!~-i,i%3?i%5?"beer":"buzz":i%5?"fizz":"fizzbuzz"),printf(
i;f(){for(i=99;i;c((i?:99))w".\n\n"))c(i)w", "),c(i)".\n"),printf(--i?"Take one down and pass it around, ":"Go to the store and buy some more, ");}


Who doesn't love unmatched parentheses in macro expansions ?

### Ungolfed:

#define c(i)                               \
printf(                                \
"%d bottle%s of %s",               \
i,                   /* Number  */ \
i-1 ? "s" : "",      /* Plural  */ \
i % 3                /* FizzBuzz*/ \
? i % 5                        \
? "beer"                   \
: "buzz"                   \
: i % 5                        \
? "fizz"                   \
: "fizzbuzz"               \
)

i;
f() {
for(i = 99; i; ) {
c(i); printf(" on the wall, ");
c(i); printf(".\n");
printf(
--i
? "Take one down and pass it around, "
: "Go to the store and buy some more, "
);

// This has been stuffed into the for increment
c((i?:99)); printf(" on the wall.\n\n");
}
}


See it live on Coliru!

# Alternate version (276 bytes)

#define c(i)printf("%d bottle%s of %s",i,i-1?"s":"",i%3?i%5?"beer":"buzz":i%5?"fizz":"fizzbuzz"),printf(
i,*w=" on the wall";f(){for(i=99;i;c((i?:99))"%s.\n\n",w))c(i)"%s, ",w),c(i)".\n"),printf(--i?"Take one down and pass it around, ":"Go to the store and buy some more, ");}

• This is super cool! I'm always shocked at how good C answers can be with string manipulation. May 13, 2017 at 2:24
• Save a few bytes by changing #define w" on the wall" to *w=" on the wall". May 14, 2017 at 0:38
• @MDXF mmh, I get the exact same byte count. Am I missing something? May 14, 2017 at 11:48
• I think they meant you can replace #define w with *w= to save bytes there. Honestly I'm not all that familiar with golfed C, but my guess is that it makes w an implicitly-defined global char*. May 14, 2017 at 15:59
• @musicman523 the issue is that the #defined w is a string literal, which is automatically pasted with adjacent string literals. If w is a variable, I have to use actual string formatting inside printf. May 14, 2017 at 16:07

# Röda, 273 bytes

f{a=bottlef= on the wallg=99 ${a}s of fizz;[$g$f,$g.
];seq 98,1|{|b|d=sd=if[b=1];c=c=fizzif[b%3=0];c.=buzzif[b%5=0];c=beerif[c=];e=$b$a$d of$c;[Take one down and pass it around, $e$f.

$e$f, $e. ]}_;[Go to the store and buy some more,$g$f.]}  Try it online! Will golf further in the morning. # PHP, 242 Bytes function f($k){return"$k bottle".(s[$k<2])." of ".([fizz][$k%3].[buzz][$k%5]?:beer);}$w=" on the wall";for($b=f($c=99);$c;)echo"$b$w, $b. ",--$c?"Take one down and pass it around":"Go to the store and buy some more",", ",$b=f($c?:99),"$w. ";  Try it online! # PHP, 244 Bytes for($e=s,$b=fizz,$c=99;$c;)echo strtr("301245, 30124. 6, 708295. ",[" bottle",$e," of ",$c,$b," on the wall",--$c?"Take one down and pass it around":"Go to the store and buy some more",$k=$c?:99,$e=s[2>$k],$b=[fizz][$k%3].[buzz][$k%5]?:beer]);


Try it online!

use function strtr

# PHP, 245 Bytes

$f=function($k)use(&$b){$b="$k bottle".(s[$k<2])." of ".([fizz][$k%3].[buzz][$k%5]?:beer);};for($w=" on the wall",$f($c=99);$c;)echo"$b$w, $b. ",--$c?"Take one down and pass it around":"Go to the store and buy some more",", {$f($c?:99)}$b$w.

";


Try it online!

use an Anonymous function in the string to get a sustring depending of the integer

Expanded

$f=function($k)use(&$b){$b="$k bottle".(s[$k<2])." of ".([fizz][$k%3].[buzz][$k%5]?:beer);};
for($w=" on the wall",$f($c=99);$c;)
echo"$b$w, $b. ",--$c?"Take one down and pass it around":"Go to the store and buy some more"
,", {$f($c?:99)}$b$w.

";

• If I didn't miscount you can save 2 bytes (250 bytes in total): function x($n){return"$n bottle".($n-1?s:'')." of ".(($n%3?'':fizz).($n%5?'':buzz)?:beer);}$y=" on the wall";for($b=99;$b;){$c=x($b);echo"$c$y, $c.↵",--$b?"Take one down and pass it around":"Go to the store and buy some more",", ".x($b?:99)."$y.↵↵";}. :) May 13, 2017 at 14:13
• @insertusernamehere You have miscount with a few changes it saves 2 Bytes more. Thank You. And you have give me a little idea to use use in combination with the anonymous function which saves 1 Byte in this version May 13, 2017 at 14:57

# 05AB1E, 151146 143 bytes

99LRv'¬ž“fizzÒÖ“#y35SÖÏJ‚˜1(è©y“ƒ¶€µ„‹€ƒîå€•…¡, ÿÏê€‚ ÿ€‰€€íÒ.“ªõ®y“ÿÏê€‚ ÿ€‰€€íÒ, “D#4£ðýs…ÿÿ.}‚‚˜'Ïê'±¥:)¦¦¬#7£ðý¨“‚œ€„€€ƒï€ƒ‚¥€ä€£, ÿ.“ª)˜»


Try it online!

# SOGL, 136135134133 131 bytes

Ƨ, o▓k
"πFT+╔¡‘oW
³³q"'bμ⁸‘oH? so}5\;3\«+"ΞQv↑χāσκN⌡κYT¡‘_,S─‘oθwoX▓
MH∫}¹±{▓WkƧ.¶oH¡"sΗ─χpēGķ¶¾3Ζ^9f.⅟▒E┌Fρ_╬a→‘KΘw⁽oXH‽M}HkW">⁸‘p


First of all, the 3rd function:

                                    ▓  name this "▓" (example input: 15)                          
³³                                     Create 4 extra copies of the top thing (number of things)  [15, 15, 15, 15, 15]
q                                    output without popping one of them                         [15, 15, 15, 15, 15]
"...‘o                              output " bottle"                                           [15, 15, 15, 15, 15]
H?   }                        if pop-1 [isn't 0]                                         [15, 15, 15, 15]
so                           output "s"                                               [15, 15, 15, 15]
5\                      push if POP divides by 5                                   [15, 15, 15, 1]
;                     swap [if divides & another number copy]                    [15, 15, 1, 15]
3\«                  push if POP divides by 3, multiplied by 2                  [15, 15, 1, 2]
+                 add those together                                         [15, 15, 3]
"...‘            push "buzz fizz fizzbuzz beer"                             [15, 15, 3, "buzz fizz fizzbuzz beer"]
...‘o       output " of " (done over here to save a byte for a quote)  [15, 15, 3, "buzz fizz fizzbuzz beer"]
θ      split ["buzz fizz fizzbuzz beer"] on spaces                [15, 15, 3, ["buzz","fizz","fizzbuzz","beer"]]
w     get the index (1-indexed, wrapping)                        [15, 15, ["buzz","fizz","fizzbuzz","beer"], "fizzbuzz"]
o    output that string                                         [15, 15, ["buzz","fizz","fizzbuzz","beer"]]
X   pop the array off of the stack                             [15, 15]


The first function:

Ƨ, o▓k
k  name this "function" "k"
Ƨ, o    output ", "
▓   execute the "bottleify" function


The second function:

"πFT+╔¡‘oW
W  call this "W"
"πFT+╔¡‘    push " on the wall"
o   output it


And the main part:

MH∫}                                     repeat 99 times, each time pushing index
¹                                    wrap in an array
±                                   reverse it
{                                  iterate over it
▓                                 execute that function
W                                execute that function
k                               execute that function
Ƨ.¶o                           output ".\n"
H¡                         push if POP-1 isn't 0 (aka 1 if pop <> 1, 0 if pop == 1)
"...‘                    push "Stake one down and pass it aroundSgo to the store and buy some more"
K                   push the first letter of that string
Θ                  split ["take one down and pass it aroundSgo to the store and buy some more" with "S"]
w                 gets the xth (1-indexed, wrapping) item of that array
⁽o               uppercase the 1st letter and output
X              pop the array off
H‽            if pop-1 [isn't 0]
M           push 100
}          ENDIF
H         decrease POP
k        execute that function
W       execute that function
">⁸‘p  output ".\n\n"


Lost a couple bytes because of a bug that O puts a newline before and after it (And somehow this goes back to V0.9 (this is V0.11 code))

# Java, 344340 339 bytes

(-4 bytes after golfing fizzbuzz; -1 byte removing stray whitespace)

interface X{static void main(String[]a){for(int i=99;i>0;System.out.printf("%s on the wall, %s.%n%s, %s on the wall.%n%n",b(i),b(i--),i<1?"Go to the store and buy some more":"Take one down and pass it around",b(i<1?99:i)));}static String b(int i){return i+" bottle"+(i>1?"s":"")+" of "+(i%3<1?"fizz":"")+(i%5<1?"buzz":i%3<1?"":"beer");}}


Slightly ungolfed (using 1-space indentation to eliminate horizontal scrolling):

interface X {
static void main(String[]a){
for(int i=99;i>0;System.out.printf("%s on the wall, %s.%n%s, %s on the wall.%n%n",
b(i),b(i--),
i<1?"Go to the store and buy some more":"Take one down and pass it around",
b(i<1?99:i)));
}
static String b(int i){
return i+" bottle"+(i>1?"s":"")+" of "+(i%3<1?"fizz":"")+(i%5<1?"buzz":i%3<1?"":"beer");
}
}


# JavaScript (ES6), 316 309 bytes

This is a full program rather than a function. Nothing very creative, it's just the naive approach (hence the bytecount!). I am using console.log() instead of alert() because many browsers have limit on the number of chars that can be displayed using alert(). Note that all the whitespaces and newlines are necessary.

a="";for(i=99;i>0;i--){b=j=>"bottle"+(j>1?"s":"");d=a=>(a%3?"":"fizz")+(a%5?"":"buzz")||"beer");w=" on the wall";o=" of ";a+=${i+" "+b(i)+o+d(i)+w+", "+i+" "+b(i)+o+d(i)}.${i>1?"Take one down and pass it around, ":"Go to the store and buy some more, "}${(y=i-1?i-1:99)+" "+b(y)+o+d(y)+w}. ;}console.log(a)  Ungolfed : let accumulator = ""; for(let i = 99; i>0; i--){ let bottleString = j => "bottle"+(j>1?"s":""), drink = a =>(a%3?"":"fizz")+(a%5?"":"buzz")||"beer", wallString = " on the wall", of=" of "; accumulator += ${i+" "+bottleString(i)+of+drink(i)+wallString+", "+i+" "+bottleString(i)+of+drink(i)}.
${i>1?"Take one down and pass it around, ":"Go to the store and buy some more, "}${(y=i-1?i-1:99)+" "+bottleString(y)+of+drink(y)+wallString}.

;
}

console.log(accumulator);


Here's the Snippet :

a="";for(i=99;i>0;i--){b=j=>"bottle"+(j>1?"s":"");d=a=>(a%3?"":"fizz")+(a%5?"":"buzz")||"beer";w=" on the wall";o=" of ";a+=${i+" "+b(i)+o+d(i)+w+", "+i+" "+b(i)+o+d(i)}.${i>1?"Take one down and pass it around, ":"Go to the store and buy some more, "}${(y=i-1?i-1:99)+" "+b(y)+o+d(y)+w}. ;}console.log(a) BTW, with this answer, I have earned the bronze badge in ! Never thought I will accomplish this ever (not that it's a big achievement, though.)! • Your d function doesn't need any ()s because ?: is right-associative, but you can actually save even more bytes using d=a=>(a%3?"":"fizz")+(a%5?"":"buzz")||"beer". – Neil May 15, 2017 at 20:52 # Retina, 230 bytes  99$*_
_\B
Take one down and pass it around, $.'#.¶¶$.'#, $.'.¶ ^ 99#, 99.¶ _ Go to the store and buy some more, 99#. # on the wall 1\b|(\d+)$& bottle$#1$*s of $&$*_
\b(_{15})+\b
fizzbuzz
\b(_{5})+\b
buzz
\b(___)+\b
fizz
_+
beer


Try it online! Explanation:


99$*_  Inserts 99 _s. _\B Take one down and pass it around,$.'#.¶¶$.'#,$.'.¶


Changes all but the last _ to the string Take one down and pass it around, $.'#.¶¶$.'#, $.'.¶, where ¶ is a newline and $.' is the count of remaining underscores. This effectively counts back from 98 to 1.

^
99#, 99.¶


Adds the first line of the first verse in "compact" format.

_
Go to the store and buy some more, 99#.


Adds the second line of the last verse. Why I need jump through hoops to use the _ I don't know, but $ seems to match twice, so I can't use that. Go figure. # on the wall  Substitutes a string which appears several times in the verse. 1\b|(\d+)$& bottle$#1$*s of $&$*_


This matches the integers in the verses, and suffixes the appropriate bottle(s) of, and expands back to unary again, in preparation to choose the beverage. (I save 1 byte on on the 99s this way.)

\b(_{15})+\b
fizzbuzz
\b(_{5})+\b
buzz
\b(___)+\b
fizz
_+
beer


Replace exact multiples with the appropriate beverage.

# sed, 468459 456 bytes

s:^:99 bottles of fizz on the wall, 99 bottles of fizz.:
p
s:99:I8:g
s:fizz:XYYZ:g
x
s:^:Take one down and pass it around, I8 bottles of XYYZ on the wall.\n:
G
x
:
g
s:XXX:fizz:g
s:Y{5}:buzz:g
s:\bX*Y*Z:beer:g
s:[XYZ]::g
y:ABCDEFGHI:123456789:
s:\b0::g
/ 1 /bq
p
x
s:^::
tc
:c
s:(\S)0:\1@:g
Td
y:ABCDEFGHI:0ABCDEFGH:
:d
y:123456789@:0123456789:
s:(XXX)*(Y{5})*(Y*Z):XY\3:g
x
b
:q
s:es:e:g
aGo to the store and buy some more, 99 bottles of fizz on the wall.


Try it online!

Requires -r flag.

## Explanation

Hold space holds the pattern of two repeating lines, with numbers represented as [A-I][0-9] (separate digits for tens and ones) and the kind of beverage represented as X*Y*Z, where X keeps track of -N mod 3, and Y of -N mod 5.

On each subsequent iteration, the numbers get decremented and the Xs and Ys get updated. Then hold space gets copied to the pattern space, turned into lines of the song, and printed.

# C, 349345 344 bytes

#define b(x)x^1?" bottles":" bottle"
#define g i-1?"Take one down and pass it around":"Go to the store and buy some more"
*w=" on the wall";*s(x){return x?x%15?x%5?x%3?"beer":"fizz":"buzz":"fizzbuzz":"fizz";}i=100;main(){while(--i){printf("%d%s of %s%s, %d%s of %s.\n%s, %d%s of %s%s.\n",i,b(i),s(i),w,i,b(i),s(i),g,i-1?i-1:99,b(i-1),s(i-1),w);}}


Well, there you go. That took an hour.

Try it online!

# Javascript (ES6), 236234233 232 bytes

for(i=99;i;console.log(z()+, ${z(_)}.${--i?'Take one down and pass it around':'Go to the store and buy some more'}, ${z()}. ))z=(o=' on the wall',j=i||99)=>j+ bottle${j>1?'s':_} of +((j%3?_:'fizz')+(j%5?_='':'buzz')||'beer')+o


Demo

// replace console.log to avoid 50-log limit in snippets:
console.log=_=>document.write(<pre>${_}</pre>) for(i=99;i;console.log(z()+,${z(_)}.
${--i?'Take one down and pass it around':'Go to the store and buy some more'},${z()}.

))z=(o=' on the wall',j=i||99)=>j+ bottle${j>1?'s':_} of +((j%3?_:'fizz')+(j%5?_='':'buzz')||'beer')+o Ungolfed i = 99 // start counter at 99 z = ( // define function z which takes arguments with defaults: o = ' on the wall', // o = defaults to ' on the wall' j = i || 99 // j = defaults to value of counter i - or 99 when i == 0 ) => j + // our current j counter ' bottle' + (j > 1 ? 's' : _) + // choose 's' when we have more than 1 bottle, or blank _ ( (j % 3 ? _ : 'fizz') + // if j % 3 is 0, add 'fizz', otherwise blank _ (j % 5 ? _ = '' : 'buzz') // if j % 5 is 0, add 'buzz', otherwise blank _ // _ gets defined here since it's the first place it's used || // if no fizz or buzz, result is a falsey empty string 'beer' // replace falsey value with 'beer' ) + o // append o while (i) { // while counter is non-zero console.log( // output string: z() + // call z without o argument ', ' + z(_) + // call z with blank _ for o to block ' on the wall' here '.\n' + ( --i // decrement i, if still non-zero: ? 'Take one down and pass it around' // otherwise: : 'Go to the store and buy some more' ) + ', ' + z() + // another call to z without o '.\n\n' ) }  # Ruby, 261 bytes 99.downto(1){|i|w=' on the wall' f=->x{a='';x%3<1&&a+='fizz';x%5<1&&a+='buzz';a<?a&&a='beer';"%d bottle%s of %s"%[x,x<2?'':?s,a]} puts [f[i]+w,f[i]+?.+$/+(i<2?'Take one down and pass it around':'Go to the store and buy some more'),f[i<2?99:i-1]+w+?.+$/*2]*', '}  Try it online! # shortC, 314 312 bytes Db(x)x^1?" bottles":" bottle" Dg i-1?"Take one down and pass it around":"Go to the store and buy some more" *w=" on the wall";*s(x){Tx?x%15?x%5?x%3?"beer":"fizz":"buzz":"fizzbuzz":"fizz";}i=100;AW--i){R"%d%s of %s%s, %d%s of %s.\n%s, %d%s of %s%s.\n",i,b(i),s(i),w,i,b(i),s(i),g,i-1?i-1:99,b(i-1),s(i-1),w  Sorry there's no explanation, but I completely forgot how this works. • You should consider adding another answer in shortC that follows the logic of this answer, to see how it golfs. Also, it looks like in both your answers you only use your macro for g once, you should be able to inline it and save a few bytes May 14, 2017 at 16:04 • Can you post the expanded version? Jun 25, 2017 at 20:58 • @CalculatorFeline The equivalent C code is already here, if that's what you're asking for Jun 25, 2017 at 21:50 # Charcoal, 307 297 bytes Ａ”｜‽2?{:×G↗”¦αＡ“6«eMηOU¶¿”¦ζＡ“9“e▷·gqε-g}”¦βＡ“9Ｂ{⦃⁺Ｂφ=；λO”¦ωＡfizz¦φＡbuzz¦γＡbeer¦ηＡ”↶C▶▶d℅d¬r·ＵS\λＴθＮevＴ◧→GM⁸ωβ”¦τＡ“M↧k↓⁺*f÷,ψＺ¢▶\¿｜Ｐ“№κ×υpξＸoＷ”¦σＡ.¶πＦ⮌…¹¦¹⁰⁰«Ａ⎇⁻ι¹αζθ¿∧¬﹪ι³¬﹪ι⁵Ａ⁺φγε¿¬﹪ι³Ａφε¿¬﹪ι⁵ＡγεＡηε⁺⁺⁺⁺⁺⁺⁺ＩιθεβＩιθεπ¿⁻ι¹Ａ⁻ι¹λＡ⁹⁹λＡ⎇⁻λ¹αζθ¿∧¬﹪λ³¬﹪λ⁵Ａ⁺φγε¿¬﹪λ³Ａφε¿¬﹪λ⁵ＡγεＡηε¿⁻ι¹ＡτδＡσδ⁺⁺⁺⁺δλθεω  Try it online! YES, WE CAN! Link to the verbose version, this can be golfed a lot, I'm sure. • Sadly you forgot to actually link to the verbose version, but that run of ⁺s looks suspicious... – Neil Dec 2, 2017 at 13:19 # tcl, 298 proc B i {set x " bottle[expr$i>1?"s":""] of [expr $i%3?$i%5?"beer":"":"fizz"][expr $i%5?"":"buzz"]"} set i 99 time {puts "$i[B $i][set w " on the wall"],$i[B $i]. Take one down and pass it around, [incr i -1][B$i]$w."} 98 puts "1[B$i]$w, 1[B$i].
Go to the store and buy some more, 99[B 9]\$w."
`