# 1, 2, Fizz, 4, Buzz

## Introduction

In our recent effort to collect catalogues of shortest solutions for standard programming exercises, here is PPCG's first ever vanilla FizzBuzz challenge. If you wish to see other catalogue challenges, there is "Hello World!" and "Is this number a prime?".

## Challenge

Write a program that prints the decimal numbers from 1 to 100 inclusive. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

## Output

The output will be a list of numbers (and Fizzes, Buzzes and FizzBuzzes) separated by a newline (either \n or \r\n). A trailing newline is acceptable, but a leading newline is not. Apart from your choice of newline, the output should look exactly like this:

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz


The only exception to this rule is constant output of your language's interpreter that cannot be suppressed, such as a greeting, ANSI color codes or indentation.

## Further Rules

• This is not about finding the language with the shortest approach for playing FizzBuzz, this is about finding the shortest approach in every language. Therefore, no answer will be marked as accepted.

• Submissions are scored in bytes in an appropriate preexisting encoding, usually (but not necessarily) UTF-8. Some languages, like Folders, are a bit tricky to score--if in doubt, please ask on Meta.

• Nothing can be printed to STDERR.

• Feel free to use a language (or language version) even if it's newer than this challenge. If anyone wants to abuse this by creating a language where the empty program generates FizzBuzz output, then congrats for paving the way for a very boring answer.

Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language.

• If your language of choice is a trivial variant of another (potentially more popular) language which already has an answer (think BASIC or SQL dialects, Unix shells or trivial Brainfuck derivatives like Alphuck and ???), consider adding a note to the existing answer that the same or a very similar solution is also the shortest in the other language.

• Because the output is fixed, you may hardcode the output (but this may not be the shortest option).

• You may use preexisting solutions, as long as you credit the original author of the program.

• Standard loopholes are otherwise disallowed.

As a side note, please don't downvote boring (but valid) answers in languages where there is not much to golf; these are still useful to this question as it tries to compile a catalogue as complete as possible. However, do primarily upvote answers in languages where the authors actually had to put effort into golfing the code.

## Catalogue

var QUESTION_ID=58615;var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";var COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk";var OVERRIDE_USER=30525;var answers=[],answers_hash,answer_ids,answer_page=1,more_answers=true,comment_page;function answersUrl(index){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+index+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(index,answers){return"https://api.stackexchange.com/2.2/answers/"+answers.join(';')+"/comments?page="+index+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:true,success:function(data){answers.push.apply(answers,data.items);answers_hash=[];answer_ids=[];data.items.forEach(function(a){a.comments=[];var id=+a.share_link.match(/\d+/);answer_ids.push(id);answers_hash[id]=a});if(!data.has_more)more_answers=false;comment_page=1;getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:true,success:function(data){data.items.forEach(function(c){if(c.owner.user_id===OVERRIDE_USER)answers_hash[c.post_id].comments.push(c)});if(data.has_more)getComments();else if(more_answers)getAnswers();else process()}})}getAnswers();var SCORE_REG=/<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;var OVERRIDE_REG=/^Override\s*header:\s*/i;function getAuthorName(a){return a.owner.display_name}function process(){var valid=[];answers.forEach(function(a){var body=a.body;a.comments.forEach(function(c){if(OVERRIDE_REG.test(c.body))body='<h1>'+c.body.replace(OVERRIDE_REG,'')+'</h1>'});var match=body.match(SCORE_REG);if(match)valid.push({user:getAuthorName(a),size:+match[2],language:match[1],link:a.share_link,});else console.log(body)});valid.sort(function(a,b){var aB=a.size,bB=b.size;return aB-bB});var languages={};var place=1;var lastSize=null;var lastPlace=1;valid.forEach(function(a){if(a.size!=lastSize)lastPlace=place;lastSize=a.size;++place;var answer=jQuery("#answer-template").html();answer=answer.replace("{{PLACE}}",lastPlace+".").replace("{{NAME}}",a.user).replace("{{LANGUAGE}}",a.language).replace("{{SIZE}}",a.size).replace("{{LINK}}",a.link);answer=jQuery(answer);jQuery("#answers").append(answer);var lang=a.language;lang=jQuery('<a>'+lang+'</a>').text();languages[lang]=languages[lang]||{lang:a.language,lang_raw:lang.toLowerCase(),user:a.user,size:a.size,link:a.link}});var langs=[];for(var lang in languages)if(languages.hasOwnProperty(lang))langs.push(languages[lang]);langs.sort(function(a,b){if(a.lang_raw>b.lang_raw)return 1;if(a.lang_raw<b.lang_raw)return-1;return 0});for(var i=0;i<langs.length;++i){var language=jQuery("#language-template").html();var lang=langs[i];language=language.replace("{{LANGUAGE}}",lang.lang).replace("{{NAME}}",lang.user).replace("{{SIZE}}",lang.size).replace("{{LINK}}",lang.link);language=jQuery(language);jQuery("#languages").append(language)}}
body{text-align:left!important}#answer-list{padding:10px;width:290px;float:left}#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="language-list"> <h2>Shortest Solution by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr> </thead> <tbody id="languages"> </tbody> </table> </div> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr> </thead> <tbody id="answers"> </tbody> </table> </div> <table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table>

• Nothing can be printed to STDERR. Is this true only when running, or also when compiling (assuming that is a separate step?) Sep 24, 2015 at 20:47
• @AShelly Only when running Sep 24, 2015 at 20:48
• I’m not sure I like the fact that you hardcoded the 100 into the challenge. That way, a program that just generates the expected output is a valid entry, but is not interesting for this challenge. I think the challenge should expect the program to input the number of items to output. Sep 24, 2015 at 23:28
• @Timwi While I agree that it would make it (only slightly) more interesting, I've very often seen FizzBuzz as strictly 1 to 100 (on Wikipedia and Rosetta Code, for example). If the goal is to have a "canonical" FB challenge, it makes sense. Sep 25, 2015 at 0:50
• A "vanilla fizzbuzz" sounds delicious. Sep 25, 2015 at 15:12

# BRASCA, 81 bytes

1b1[x0aB:b3%0=[xzziFoooo1a0]xB:b5%0=[xzzuBoooo0A1+a]xA0=[xB:bn0]xB1+:bH1+<lo]


Try it online!

There'll be an explanation coming soon. The tio link is the interpreter split over the header and footer in such a way that the program can be entered into the code box.

1F:(F.Z4*1+<^0A:F.3\0=["Fizz"1A:]F.5\0=["Buzz"A.1+A:]A.0=[F.!]"!"F.1+F:)$ Try it online! Yet another fizzbuzz. Polyglots both versions listed and beats the current answer. The funny thing is that I came up with this independently of the other answer and managed to use the same approach. # Javascript, 99 bytes This isn't a good, or small solution, but it works: for(let i=1;i<101;i++){console.log((i%3==0&&i%5==0)?"FizzBuzz":(i%3==0)?"Fizz":(i%5==0)?"Buzz":i);}  Explanation: for (let i=1;i<101;i++) // Loop through, until reaching 100 { console.log( (i%3==0 // If I is a multiple of 3 && // And i%5==0 // If I is a multiple of 5 )?"FizzBuzz": // Print "FizzBuzzz" (i%3==0)?"Fizz": // If I isn't either of those, check whether I is a multiple of 3, if so, print "Fizz" (i%5==0)?"Buzz" // If I isn't a multiple of 3, check whether I is a multiple of 5, if so, print "Buzz" :i // Else, just print i ); }  # Phooey, 53 bytes [100+1>&<@@%3{"Fizz">&1<}&%5{"Buzz">&1<}&>{<$i>}"
"<]


Try it online!

Outgolfed the creator at his own language. 😏


[100            while cell is not 100
+1             increment cell
>&<            set fizzed flag - empty stack is zero
@@             push two copies to the stack
%3             set cell to cell mod 3
{              if cell is not zero
"Fizz"         print fizz
>&1<           set fizzed flag
}              endif
&              pop original value from stack
%5{"Buzz">&1<} repeat for buzz
&              pop again
>{             if fizzed flag is zero
^^!)=^=)=^^$v)v^|^^v)v1^v)av^^v)av^v)v^>(^/\(/>(>t/%&/&%(1&/1(%11@/@%11(1@/1(&p&(@p@(&/Fizz(@/Buzz(|p001(|(/0x/1\0(0p_1(0_/_(1p2(22/4(42/6(44/8(2p3(4p5(6p7(8p9(_(/=\=(==  Try it online! There is already a /// answer, but it is pretty boring. I thought I would try to make a more algorithmic one, even though it is a little longer ;) Ungolfed: Try it online! # CSASM v2.1.2.1, 325 bytes func main: push 1 pop$a
.lbl a
clf.o
push $a push 15 rem push 0 comp push$f.o
brtrue e
push $a push 3 rem push 0 comp push$f.o
brtrue b
push $a push 5 rem push 0 comp push$f.o
brtrue d
push $a print.n br c .lbl b push "Fizz" print.n br c .lbl d push "Buzz" print.n br c .lbl e push "FizzBuzz" print.n .lbl c clf.o inc$a
push $a push 101 comp push$f.o
brfalse a
ret
end


Commented and Ungolfed:

func main:
; Initilize the counter in the accumulator
push 1
pop $a .lbl loop ; Reset the Comparison flag clf.o ;$a % 15 == 0
push $a push 15 rem push 0 comp ; Jump to label "printFizzBuzz" if the Comparison flag is true push$f.o
brtrue printFizzBuzz

; $a % 3 == 0 push$a
push 3
rem
push 0
comp

push $f.o brtrue printFizz ;$a % 5 == 0
push $a push 5 rem push 0 comp ; Jump to label "printBuzz" if the Comparison flag is true push$f.o
brtrue printBuzz

; None of the above were true.  Just print the number itself
push $a print.n br checkCounter .lbl printFizz ; Print "Fizz" push "Fizz" print.n br checkCounter .lbl printBuzz ; Print "Buzz" push "Buzz" print.n br checkCounter .lbl printFizzBuzz ; Print "FizzBuzz" push "FizzBuzz" print.n .lbl checkCounter ; Clear the Comparison flag clf.o inc$a

; $a == 101 push$a
push 101
comp
push $f.o ; Keep looping until the above is false brfalse loop ret end $$$$  # Pxem, Filename: 96 81 bytes + Content: 0 bytes = 96 81 bytes. Thanks, Neil, for providing a workaround for -15 bytes! • Filename (some are escaped): \020.z.t.m\005.%\001.yXXbuzz.a.m\003.%\001.yXXfizz.a.c.c.z.m\017.-.nXX@.a.c@.z.pXX.a.s\n.o.m\001.+.ct.a • Content: empty. Try it online! (with pxem.posixism) ## With comments XX.z .a\020.zXX.z # push 16; while :; do .a.tXX.z # heap = pop! .a.m\005.%\001.yXXbuzz.aXX.z # while 1>heap%5; do push "buzz"; break; done .a.m\003.%\001.yXXfizz.aXX.z # while 1>heap%3; do push "fizz"; break; done .a.c.c.z.m\017.-.nXX@.aXX.z # if empty?; then print(heap-15); push "@"; fi # this is how while empty?; do something; done works: # ".c.c.z bla bla bla .a" # NOTE: Fail on pxemi dot 7z and RPxem # They need some patches before installing # Implementation needs to be document-compliant # PS. RPxem v0.0.7 fixed dotC .a.c@.z.pXX.aXX.z # if top!="@"; then print pop all!; fi .a.sXX.z # pop! .a\n.oXX.z # print "\n" .a.m\001.+XX.z # push heap; add one to it .a.ct.aXX.z # break if equal to 116 .a  ## Note • In Pxem, unlike other stack-based languages, subtraction and division does NOT rely on positions of two items; .- does push(abs(pop-pop)), .$ and .% stand for x=pop; y=pop; push(int(x>y?x/y:y/x)) and x=pop; y=pop; push(int(x>y?x%y:y%x)) respectively. Thus, when you try to do something like 13/17 or 13%17, you need to check which are greater first.
• To avoid the specification, the program loops from 16 to 115.

## Old version

1

• To work around that division, could you not loop from 16 to 116, but subtract 15 before printing?
– Neil
Mar 20, 2021 at 21:57
• @Neil thank you!
– user100411
Mar 21, 2021 at 0:14

# Stax, 21 bytes

f(incr($1))')')f(1)  Try it online! # M4, 143 bytes, SUSv2-compatible. define(f,ifelse($1',101,,g($1',ifelse(eval($1%3),0,fizz)'ifelse(eval($1%5),0,buzz)) f(incr($1))')')define(g,ifelse(len($2),0,$1,$2)')f(1)  Try it online! I am not familiar with M4, but I tried some bests. What quotations can be removed? ## With comments dnl def f(n): return "" if n==101 else g(n,("fizz" if n%3==0 else "")+("buzz" if n%5==0 else "")+"\n"+f(n+1)) define(f,ifelse($1',101,',g($1',ifelse(eval($1%3),0,fizz)'ifelse(eval($1%5),0,buzz)) f(incr($1))')')dnl
dnl def g(n,s): return n if len(s)==0 else n
define(g,ifelse(len($2),0,$1,$2)')dnl f(1)  # Pinecone, 90 bytes i:1|i<101|i:i+1@(i%3+i%5=0?print:"FizzBuzz"|i%3=0?print:"Fizz"|i%5=0?print:"Buzz"|print:i)  # BRASCA, 58 bytes 1Hr,[0a:3%0=[a0zziF[o]]x:5%0=[a0zzuB[o]]A$=[x:n0]xxlo]


Try it online!

# Knight, 5048 43 bytes

;=n 0W>101=n+1nO|+*"Fizz"!%n 3*"Buzz"!%n 5n


Try it online!

-2 bytes: use string multiplication instead of IF

-5 bytes: I completely overlooked |, I assumed it had C semantics.

Ungolfed:

# start with n at 0
; = n 0
# increment n and loop while less than 101
: WHILE > 101 (= n + 1 n)
# outlined from the output for clarity
# concatenate:
; = fizzbuzz +
# Fizz if n % 3 == 0
: * "Fizz" ! (% n 3)
# Buzz if n % 5 == 0
: * "Buzz" ! (% n 5)
# If fizzbuzz is not empty, output it, otherwise output n
: OUTPUT | fizzbuzz n


# C++20, 202 bytes

this is uncompetitive, but this was so fun I couldn't help but post it here.

#include <bits/stdc++.h>
using namespace std;auto f=[](int i){return i%15?(i%5?(i%3?to_string(i):"Fizz"):"Buzz"):"FizzBuzz";};int main(){for(auto i:views::iota(1,100)|views::transform(f))cout<<i<<endl;}

• you have an extra space in 1, 100 Jul 14, 2021 at 3:19
• @hyper-neutrino oh darn thanks Jul 14, 2021 at 3:23

# Python 3, 59 bytes

for i in range(100):print(i%3//2*'Fizz'+i%5//4*'Buzz'or-~i)


# PostScript, 73 bytes

Using binary encoding:

000000 31 88 01 88 64 7b 2f 69 92 3e 92 33 28 46 69 7a
000010 7a 42 75 7a 7a 29 69 88 0f 28 42 75 7a 7a 29 69
000020 20 35 28 46 69 7a 7a 29 69 88 03 33 7b 92 6a 30
000030 92 3d 7b 2f 69 92 3e 92 33 7d 7b 92 75 7d 92 55
000040 7d 92 83 69 20 3d 7d 92 48


Try it online! (thanks to tail spark rabbit ear, ignore TIO's character count).

This is a straight-forward encoding of the following 101 byte program (in binary encoding, 136 n is a signed 8-bit integer and 146 n is command n from the system name encoding list in appendix F of the PostScript language reference).

1 1 100{/i exch def(FizzBuzz)i 15(Buzz)i 5(Fizz)i 3 3{mod 0 eq{/i exch def}{pop}ifelse}repeat i =}for


Try it online!

The non-binary encoded version can be reduced to 98 bytes if we don't mind leaving /i on the stack.

/i 1 1 100{def(FizzBuzz)i 15(Buzz)i 5(Fizz)i 3 3{mod 0 eq{/i exch def}{pop}ifelse}repeat i =/i}for


Try it online!

• I made you a TIO thing of the binary.
– user100411
Aug 8, 2021 at 9:16
• @tailsparkrabbitear: Thanks for that. I hadn't even considered that the TIO bash would include Ghostscript. Perhaps put a note on the Postscript Code Golf tips page. Aug 8, 2021 at 12:22

# jq, 98 82 bytes

range(1;101)|if.%15<1then"FizzBuzz"elif.%3<1then"Fizz"elif.%5<1then"Buzz"else. end


Try it online!

Yet to golf it!

Removed superfluous spaces thanks to @DLosc.

• Some simple golfs get you down to 82 bytes Sep 4, 2021 at 4:00
• Thanks @DLosc, I didn't realize you could remove the spaces! Sep 4, 2021 at 4:31

# Rockstar, 138135 133 bytes

F takes I&S
let M be N/I
turn up M
if N-I*M
S's""

return S

N's0
while N-100
let N be+1
say F taking 3,"Fizz"+F taking 5,"Buzz" or N


Try it here (Code will need to be pasted in)

# Pure Bash, 70 bytes69 bytes68 bytes 63 + 1 = 64 bytes

The following program must be saved as x, which is for 1 byte of penalty.

''
((++x%3))||Fizz
((x%5))||$_\Buzz echo${_:-$x} ((x>99))||. x  Try it online! • OBTW I am outputting garbages to stderr, which may be against the rules. – user100411 Nov 11, 2021 at 22:30 # RickRoll-Lang, 185 bytes takemetourheart give a up [*range(1,101)[::-1]] togetherforeverandnevertopart give i up a.pop() give s up "Fizz"*(i%3<1)+"Buzz"*(i%5<1) ijustwannatelluhowimfeeling [str(i),s][s>""]+"\n"  ### Explanation: RickRoll-Lang keywords do not need spaces between them takemetourheart -- main() function declaration give a up [*range(1,101)[::-1]] -- set a to reverse of int range [1, 101) togetherforeverandnevertopart -- infinite loop give i up a.pop() -- pop last element of a and store in i give s up "Fizz"*(i%3<1)+"Buzz"*(i%5<1) -- string multiplcation to form fizzbuzz depending on modulus remainders ijustwannatelluhowimfeeling [str(i),s][s>""]+"\n" -- print i if s is empty else s and a newline -- implicit "say goodbye" (end block) at the end -- another say goodbye  Try it online! # jq, 78 bytes range(1;101)|. as$n|[(select(.%3==0)|"Fizz"),(select(.%5==0)|"Buzz")]|add//$n  # Kotlin, 117 bytes {for(i in 1..100){println("${if(i%3<1)"fizz" else ""}${if(i%5<1)"buzz" else ""}${if(!(i%3<1||i%5<1))"\$i" else ""}")}}


Try it online!

as usual as it gets

edit: i hope the extra \n at the end is not a problem

# SQLite, 183 bytes

WITH F AS(SELECT 1 AS N UNION ALL SELECT N+1 FROM F WHERE N<100)SELECT CASE WHEN N%15=0 THEN'FizzBuzz'WHEN N%5=0 THEN'Buzz'WHEN N%3=0 THEN'Fizz'ELSE CAST(N AS VARCHAR)END AS F FROM F;


Try it online!

###### Ungolfed code:
WITH F AS(
SELECT
1 AS N
UNION ALL
SELECT
N + 1
FROM
F
WHERE
N < 100
)
SELECT
CASE WHEN N % 15 = 0 THEN 'FizzBuzz' WHEN N % 5 = 0 THEN 'Buzz' WHEN N % 3 = 0 THEN 'Fizz' ELSE CAST(N AS VARCHAR) END AS F
FROM
F;


# Boo, 114 bytes

for i in range(1,101):
if i%15==0:print'FizzBuzz'
elif i%5==0:print'Buzz'
elif i%3==0:print'Fizz'
else:print i


Try it online!

# Squirrel, 131 bytes

for(local i=0;i++<100;)if(i%15==0)print("FizzBuzz\n")else if(i%5==0)print("Buzz\n")else if(i%3==0)print("Fizz\n")else print(i+"\n")


Try it online!

### This is the original code that I created:

function fizzBuzz(n) {
for (local i = 1; i <= n; i += 1) {
if (i % 15 == 0)
print ("FizzBuzz\n")
else if (i % 5 == 0)
print ("Buzz\n")
else if (i % 3 == 0)
print ("Fizz\n")
else {
print (i + "\n")
}
}
}

fizzBuzz(100);


# Scala, 103 94 bytes

for{i<-1 to 100;s=(if(i%3==0)"Fizz"else"")+(if(i%5==0)"Buzz"else"")}println(if(s=="")i else s)


thx @Ben (shortened by 9 bytes)

• You can save 9 bytes by using a for comprehension: for{i<-1 to 100;s=(if(i%3==0)"Fizz"else"")+(if(i%5==0)"Buzz"else"")}println(if(s=="")i else s)
– Ben
Oct 2, 2015 at 20:57

# Python 2, 72 bytes

for x in range(100):print('Fizz'*(x%3>1)+'Buzz'*(x%5>3)or str(x+1))+'\n'


Not as clever as feersum's solution, but it avoids casting exec magic.

EDIT: with just two more parentheses, it works in Python 3 AND Python 2:

for x in range(100):print(('Fizz'*(x%3>1)+'Buzz'*(x%5>3)or str(x+1))+'\n')

• even simpler, supress +'\n' and some parenbthesis : for x in range(100):print('Fizz'*(x%3>1)+'Buzz'*(x%5>3)or x+1) so 63 bytes Pthon 3
– Malo
Sep 2, 2021 at 19:53