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


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


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:


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.

  • Unlike our usual rules, 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.


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>

  • 1
    \$\begingroup\$ Nothing can be printed to STDERR. Is this true only when running, or also when compiling (assuming that is a separate step?) \$\endgroup\$ – AShelly Sep 24 '15 at 20:47
  • \$\begingroup\$ @AShelly Only when running \$\endgroup\$ – Beta Decay Sep 24 '15 at 20:48
  • \$\begingroup\$ 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. \$\endgroup\$ – Timwi Sep 24 '15 at 23:28
  • 7
    \$\begingroup\$ @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. \$\endgroup\$ – Geobits Sep 25 '15 at 0:50
  • 59
    \$\begingroup\$ A "vanilla fizzbuzz" sounds delicious. \$\endgroup\$ – Reinstate Monica iamnotmaynard Sep 25 '15 at 15:12

267 Answers 267


Hexagony, 91 bytes

Thanks for the bounty :)

Wow, I would never have imagined I could beat Martin’s Hexagony solution. But—who would have thunk it—I got it done. After several days of failure because I neither had the Hexagony colorer nor the EsotericIDE to check my solution. I got several aspects of the specification wrong, so I produced a few wrong “solutions” just using pen and paper and a text editor. Well, finally I overcame my laziness and cloned both repositories, downloaded VisualStudio and compiled them. Wow, what useful tools they are! As you can see, I am far from being someone you’d call a programmer (I mean, come on! I didn’t even have VisualStudio installed, and have pretty much no clue about how to compile a program) ;)

It still took me a while to find a working solution, and it is quite crammed and chaotic, but here it is in all its glory:

Fizzbuzz in a size 6 hexagon:


Hexagonal layout:

      3 } 1 " $ .
     ! $ > ) } g 4
    _ . { $ ' ) ) \
   < $ \ . \ . @ \ }
  F \ $ / ; z ; u ; <
 % < _ > _ . . $ > B /
  < > } ) ) ' % < > {
   > ; e " - < / _ %
    ; \ / { } / > .
     \ ; . z ; i ;
      . . > ( ( '

And the beautiful rendition, thanks to Timwi’s Hexagony Colorer:

Colorized Hexagony FizzBuzz solution

So, here is a 110 seconds long GIF animation at 2 fps, showing the program flow during the first 6 numbers 1, 2, Fizz, 4, Buzz, Fizz, the first 220 ticks of the program (click on the image for the full size):

enter image description here

My goodness, thanks to the Natron compositing software the animation of the pointer was still tedious to create, but manageable. Saving 260 images of the memory was less amusing. Unfortunately EsotericIDE can’t do that automatically. Anyways, enjoy the animation!

After all, once you wrap your head around the memory model and the rather counterintuitive wrapping of paths that cross the borders of the hexagon, Hexagony is not that hard to work with. But golfing it can be a pain in the butt. ;)

It was fun!

  • 1
    \$\begingroup\$ Very nice! :) That's what I get for forgetting to try side-length 6 myself. ;) (Would be interesting to see if my solution fits into side-length 6 more easily though.) \$\endgroup\$ – Martin Ender Mar 6 '16 at 9:45
  • \$\begingroup\$ @MartinBüttner I would love to see it :) \$\endgroup\$ – M L Mar 6 '16 at 16:56
  • 2
    \$\begingroup\$ I am less of a programmer than you, because what is Visual Studio? :P \$\endgroup\$ – Rɪᴋᴇʀ Mar 10 '16 at 2:42
  • 5
    \$\begingroup\$ Unfortunately EsotericIDE can’t do that automatically. — Please go right ahead and file a feature suggestion, I might get around to doing that some day :) \$\endgroup\$ – Timwi Mar 10 '16 at 13:22
  • 1
    \$\begingroup\$ (oops this comes up after 6 months of last reply) You may golf off 1 byte from the end of the program by shifting the grey path by 1 byte and placing a "Cancelling op" in the orange path like 3}1"$.!$>)}g4_'{$))}\<$\.\.@\;F\$/;z;u;<%<_>_..$>B/<>}))'%<>{>;e"-</_%;\/{}/>.\)(z;i;..>('.Now there is an extra ( after the z, which can be "cancelled" with a ) or by putting the z there. Now it is a ) which pushes all commands on the orange path 1 tick later, and got back with the no-op that was on line 3. Btw I also installed Visual Studio just due to Hexagony Colorer and Esoteric IDE :P \$\endgroup\$ – Sunny Pun Oct 14 '16 at 3:50

Python 2, 56

i=0;exec"print i%3/2*'Fizz'+i%5/4*'Buzz'or-~i;i+=1;"*100
  • 6
    \$\begingroup\$ Dang, that's bloody genius. Can I steal your idea to multiply the string by the mod-result? \$\endgroup\$ – AdmBorkBork Sep 24 '15 at 20:01
  • \$\begingroup\$ @TimmyD Go ahead. \$\endgroup\$ – feersum Sep 24 '15 at 20:06
  • 15
    \$\begingroup\$ A different method for 56 (from here): i=1;exec"print'FizzBuzz'[i%-3&4:12&8-i%5]or i;i+=1;"*100. Anyone want to brute force search expressions to try to optimize the bit bashing? \$\endgroup\$ – xnor Sep 25 '15 at 5:35
  • 1
    \$\begingroup\$ Very nice technique, I love the division of the modulo result to make it binary! I have an improvement to get your method down to 54 chars... Of course I wouldn't post it as an answer without your permission (since it's ~95% your answer) ;) \$\endgroup\$ – Tersosauros Mar 6 '16 at 13:09
  • 2
    \$\begingroup\$ @Tersosauros Go ahead... my method is not very hard to find and has no doubt been independently discovered by many people. \$\endgroup\$ – feersum Mar 6 '16 at 21:16

Labyrinth, 94 bytes

\ } 01/3%70.105
" :   @ "     .
"  =";_""..:221
+  _
"! 5%66.117
_:= "     .

Sub-100! This was a fun one.


Let's start with a brief primer on Labyrinth – feel free to skip this if you're already familiar with the basics:

  • Labyrinth has two stacks – a main stack and an auxiliary stack. Both stacks have an infinite number of zeroes at the bottom, e.g. + on an empty stack adds two zeroes, thus pushing zero.

  • Control flow in Labyrinth is decided by junctions, which look at the top of the stack to determine where to go next. Negative means turn left, zero means go straight ahead and positive means turn right... but if we hit a wall then we reverse direction. For example, if only straight ahead and turn left are possible but the top of the stack is positive, then since we can't turn right we turn left instead.

  • Digits in Labyrinth pop x and push 10*x + <digit>, which makes it easy to build up large numbers. However, this means that we need an instruction to push 0 in order to start a new number, which is _ in Labyrinth.

Now let's get to the actual code!

enter image description here


Execution starts from the " in the top-left corner, which is a NOP. Next is ), which increments the top of the stack, pushing 1 on the first pass and incrementing n on every following pass.

Next we duplicate n with :. Since n is positive, we turn right, executing } (shift top of main stack to auxiliary) and :. We hit a dead end, so we turn around and execute } and : once more, leaving the stacks like

Main [ n n | n n ] Aux

Once again, n is positive and we turn right, executing _101/ which divides n by 101. If n is 101 then n/101 = 1 and we turn into the @, which terminates the program. Otherwise, our current situation is

Main [ n 0 | n n ] Aux

Orange 1 (mod 3)

3 turns the top zero into a 3 (10*0 + 3 = 3) and % performs a modulo. If n%3 is positive, we turn right into the yellow ". Otherwise we perform 70.105.122:.., which outputs Fizz. Note that we don't need to push new zeroes with _ since n%3 was zero in this case, so we can exploit the infinite zeroes at the bottom of the stack. Both paths meet up again at light blue.

Light blue

The top of the stack is currently n%3, which could be positive, so the _; just pushes a zero and immediately pops it to make sure we go straight ahead, instead of turning into the @. We then use = to swap the tops of the main and auxiliary stacks, giving:

Main [ n | n%3 n ] Aux

Orange 2 (mod 5)

This is a similar situation to before, except that 66.117.122:.. outputs Buzz if n%5 is zero.

Dark blue

The previous section leaves the stacks like

Main [ n%5 | n%3 n ] Aux

{ shifts the n%3 back to the main stack and * multiplies the two modulos.

If either modulo is zero, the product is zero so we go straight into yellow. = swaps the top of the stacks and _ pushes a zero to make sure we go straight ahead, giving

Main [ n 0 | 0 ] Aux

Otherwise, if both modulos are nonzero, then the product is nonzero and we turn right into green. = swaps the tops of the stacks, giving

Main [ n | (n%5)*(n%3) ] Aux

after which we use : to duplicate n, turn right, then use ! to output n.


At this point, the main stack has either one or two items, depending on which path was taken. We need to get rid of the zero from the yellow path, and to do that we use +, which performs n + 0 in some order for both cases. Finally, \ outputs a newline and we're back at the start.

Each iteration pushes an extra (n%5)*(n%3) to the auxiliary stack, but otherwise we do the same thing all over again.

  • 7
    \$\begingroup\$ Loving the explanation. \$\endgroup\$ – The_Basset_Hound Sep 27 '15 at 23:08

Perl 5, 49 bytes

46 bytes script + 3 bytes -E"..."

Using say (which requires -E"...") can reduce this further to 46 bytes since say automatically includes a newline (Thanks @Dennis!):

say'Fizz'x!($_%3).Buzz x!($_%5)||$_ for 1..100

Perl 5, 50 bytes

print'Fizz'x!($_%3).Buzz x!($_%5)||$_,$/for 1..100
  • \$\begingroup\$ You can save a few bytes by using say. \$\endgroup\$ – Dennis Sep 25 '15 at 6:15
  • \$\begingroup\$ You broke the scoreboard... \$\endgroup\$ – LegionMammal978 Sep 27 '15 at 12:10
  • \$\begingroup\$ @LegionMammal978 Yes. Yes I did... I'll try and re-word the title then! Argh! \$\endgroup\$ – Dom Hastings Sep 27 '15 at 12:47
  • \$\begingroup\$ Isn't -E"..." 8 bytes? Space + Dash + Option + Argument (+ Quoting). \$\endgroup\$ – Erik the Outgolfer Sep 22 '16 at 11:00
  • 1
    \$\begingroup\$ @EriktheGolfer so since I posted this, the consensus is that -E is 0 bytes, but since primo's answer was scored excluding the quotes, I opted to make it fair and include the quotes in mine and +1 for -E. The reason it's accepted as free is Perl is usually run via perl -e and perl -E is no more bytes (I thought -M5.010 or use 5.010 can be free as well, but perhaps not re-reading the meta post). When adding -p or -n this is counted as +1 as you would run with perl -pe. Hope that helps! Meta reference: meta.codegolf.stackexchange.com/a/7539 \$\endgroup\$ – Dom Hastings Sep 22 '16 at 11:30

Ruby, 50 bytes

Requires version 1.8, which seems to be popular among golfers:


In modern Ruby, you replace ?d with 100 for a 51-byte solution.

This seems to be the world record.

  • 1
    \$\begingroup\$ That is diabolical, love it. \$\endgroup\$ – Camden Narzt Sep 28 '15 at 1:13
  • \$\begingroup\$ ?d is just 100. The FizzBuzz string has a newline in it, this is valid in Ruby. string[i, s] is a slice, starting at character i (0-indexed), going on for s characters, ignoring indices pointing outside the string. If the argument to puts already has a newline, it is chopped off. The formula should be simple to read? It does all the work here. I wouldn't've found it without the help of some really pro Ruby golfers. \$\endgroup\$ – Lynn Sep 30 '15 at 21:34
  • \$\begingroup\$ side note: if you were allowed to add 0 at the beginning of input(you're not), 2 bytes could be saved by using ?e.times instead. \$\endgroup\$ – Shelvacu Nov 12 '15 at 6:11
  • \$\begingroup\$ Can you explain the [i=n**4%-15,i+13] part please? Can't seem to wrap my head around it \$\endgroup\$ – Piccolo Aug 4 '18 at 23:02
  • 2
    \$\begingroup\$ @Piccolo Does this snippet help? If i==-14 the slice is out of bounds so we get nil. If i==-9 we slice i+13==4 characters starting from the 9th character from the end, so 'Fizz'. If i==-5 we slice 8 characters starting from the 5th character from the end, so 'Buzz\n'. (We try to slice 8 but there are only 5, so we get 5.) Et cetera. \$\endgroup\$ – Lynn Aug 4 '18 at 23:15

Java, 130 bytes

This is for recent Java versions (7+). In older ones you can shave some more off using the enum trick, but I don't think the logic gets any shorter than this (86 inside main).

class F{public static void main(String[]a){for(int i=0;i++<100;)System.out.println((i%3<1?"Fizz":"")+(i%5<1?"Buzz":i%3<1?"":i));}}
  • \$\begingroup\$ I don't think the initializer block trick helps here, since the question specifies empty stderr. \$\endgroup\$ – feersum Sep 24 '15 at 19:47
  • \$\begingroup\$ Hmm. I know the static trick prints to stderr, but I thought enum ran cleanly. Good to know :) \$\endgroup\$ – Geobits Sep 24 '15 at 19:49
  • 4
    \$\begingroup\$ beat me by 14 bytes! Using <1 instead of ==0 is a great way to save! \$\endgroup\$ – ESP Nov 8 '15 at 18:25
  • 2
    \$\begingroup\$ class F{public static -> interface F{static in java 8 \$\endgroup\$ – TheNumberOne Nov 28 '15 at 15:53
  • 1
    \$\begingroup\$ That's not quite how enums work. You would have to do enum F{;public..., so you wouldn't actually be saving any bytes. \$\endgroup\$ – HyperNeutrino Mar 7 '16 at 2:56

Pyth, 30


Try it here


VS100                            : for N in range(1,101)
     |                           : logical short-circuiting or
      +*!%N3"Fizz"               : add "Fizz" * not(N % 3)
                                 : Since not gives True/False this is either "" or "Fizz"
                  *!%N5"Buzz"    : Same but with 5 and Buzz
                             N   : Otherwise N
                                 : The output of the | is implicitly printed with a newline

Retina, 317 139 134 132 70 63 60 55 bytes


Try it online!



The . is the global silent flag which turns off implicit output at the end of the program. 100{ wraps the rest of the program in a loop which is executed for 100 iterations. Finally, the stage itself just inserts a _ at the beginning of the string, which effectively increments a unary loop counter.


More configuration. *\( wraps the remainder of the program in a group, prints its result with a trailing linefeed, but also puts the entire group in a dry run, which means that its result will be discarded after printing, so that our loop counter isn't actually modified. a is a custom regex modifier which anchors the regex to the entire string (which saves a byte on using ^ and $ explicitly).

The atomic stage itself takes care of Fizz. Divisibility by 3 can easily be checked in unary: just test if the number can be written as a repetition of ___. If this is the case, we prepend Fi; to the string. The semicolon is so that there is still a word boundary in front of the number for the next stage. If we turned the line into Fizz___... the position between z and _ would not be considered a boundary, because regex treats both letters and underscores as word characters. However, the semicolon also allows us to remove the zz duplication from Fizz and Buzz.


We do the exact same for divisibility by 5 and Bu;, although we don't need to keep the _s around this time. So we would get a results like


This makes it very easy to get rid of the underscores only in those lines which contain Fizz, while also filling in the zzs:


That is, we turn each semicolon into zz but we also consume all the _s right after it. At this point we're done with FizzBuzz in unary. But the challenge wants decimal output.


& indicates a conditional: this stage is only executed if the string contains an underscore. Therefore, Fizz, Buzz and FizzBuzz iterations are left untouched. In all other iterations (i.e. those which are neither divisible by 3 nor 5), we just count the number of characters, converting the result to decimal.


gs2, 1


A quote from Mauris, the creator of gs2:

I wanted to one-up goruby's 1-byte Hello, world!, so... This prints "1\n2\nFizz\n4\nBuzz\n...". :)

Update: Added 27-byte answer that doesn't use f.


Perl 5, 45 bytes


Requires the -E option, counted as one. This must be run from the command line, i.e.:

perl -Esay((Fizz)[$_%3].(Buzz)[$_%5]or$_)for+1..100

Quotes around the command are unnecessary, if one avoids using spaces, or any other characters which can act as command line separators (|, <, >, &, etc.).

Perl 5, 48 bytes

print+(Fizz)[$_%3].(Buzz)[$_%5]||$_,$/for 1..100

If command line options are counted as one each, -l would save one byte (by replacing $/). By Classic Perlgolf Rules, however, this would count 3: one for the -, one for the l, and one for the necessary space.

  • \$\begingroup\$ You can use say, with the -E switch, which has edit distance 1 to -e, so it should count as 1 byte. \$\endgroup\$ – Dennis Sep 25 '15 at 6:24
  • \$\begingroup\$ Hey primo, I feel like I'm cheating in my answer for using say, I've assumed that -E can be used in place of -e which would bring you down to 44 rather than 46. I don't think it's fair that I'm scoring differently to you, what's the preferred scoring mechanism? I generally use print to avoid this! Closest to a consensus would be this? \$\endgroup\$ – Dom Hastings Sep 25 '15 at 16:15
  • \$\begingroup\$ My personal take is that every additional byte on the command line should score 1. In particular for say, if your code can be written on one line avoiding any OS separators, score 1 for -E. If you need to use quotes, e.g. -E"$a||$b", score 3. If you can't get it on one line, score 5 for -M5.01. But at that point you'd probably be better off using -l. I don't agree that it should be free by default, for two reasons: 1) the improvement is trivial and uninteresting, and 2) there is no version of the interpreter for which it is enabled by default. \$\endgroup\$ – primo Sep 25 '15 at 16:39

beeswax, 104 89 81 bytes

Denser packing allowed for cutting off 8 more bytes.

Shortest solution (81 bytes), same program flow, different packing.


Changing the concept enabled me to cut down the code by 15 bytes. I wanted to get rid of the double mod 5 test in the solution, so I implemented a flag.

Short explanation:

if n%3=0 Fizz gets printed, and the flag gets set. The flag is realized simply by pushing the top lstack value onto the gstack (instruction f).

If n%5=0, then either n%3=0(FizzBuzz case) or n%3>0(Buzz case). In both cases, Buzz gets printed, and the flag reset by popping the stack until it’s empty (instruction ?).

Now the interesting cases:

If n%5>0, then either we had n%3=0 (printing Fizz case, n must not be printed) or n%3>0 (Fizz was not printed, so n has to be printed). Time to check the flag. This is realized by pushing the length of gstack on top of gstack (instruction A). If n%3 was 0 then the gstack length is >0. If n%3 was >0, the gstack length is 0. A simple conditional jump makes sure n gets only printed if the length of gstack was 0.

Again, after printing any of n, Fizz, and/or Buzz and the newline, the gstack gets popped twice to make sure it’s empty. gstack is either empty [], which leads to [0] after instruction A (push length of gstack on gstack), or it contains one zero ([0],the result of n%3), which leads to [0 1], as [0] has the length 1. Popping from an empty stack does not change the stack, so it’s safe to pop twice.

If you look closer you can see that, in principle, I folded

>      q



which helps to get rid of the all the wasted space between A and < at the end of the following row in the older solution below:

q?{@b'gA<       p      <

New concept solution (89 bytes) including animated explanation:

q?@ <
 q?{@b'gA<       p      <

Hexagonal layout:

   q ? @   <
    q ? { @ b ' g A <               p             <
 p ? < @ ` z z u B ` b ' % ~ 5 F @ < f ` z z i F ` b ' <
> N @ 9 P ~ 0 + . ~ @ ~ - " ; ~ P " # " _ " 1 F 3 ~ % d

Animation of the first 326 ticks at 2 fps, with local and global stacks, and output to STDOUT.

beeswax FizzBuzz animation

For comparison, below are the path overlays of the older, more complex solution. Maybe it’s also the prettier solution, from a visual standpoint ;)

Program with path overlay

  • 2
    \$\begingroup\$ This is as crazy and beautiful as Hexagony. Have a +1! \$\endgroup\$ – ETHproductions Feb 26 '16 at 17:08
  • \$\begingroup\$ @ETHproductions I still need to give Hexagony a try, but from what I can tell from the language specs, my beeswax doesn’t even come close to the craziness of Hexagony. \$\endgroup\$ – M L Feb 26 '16 at 17:17
  • \$\begingroup\$ Let us continue this discussion in chat. \$\endgroup\$ – M L Dec 3 '16 at 20:53
  • \$\begingroup\$ How are you making those animations? \$\endgroup\$ – baordog Aug 19 '18 at 3:32

><>, 68 66 65 64 bytes

1\2+2foooo "Buzz"<

The only trick is to multiply remainders as a condition to number printing. That way, if one of them is 0 we won't print the number.

You can try it here.

Saved one byte thanks to Sp3000 and another thanks to randomra. Many thanks!

  • 1
    \$\begingroup\$ Very well golfed, I love the reuse of the "\" on the first line and the one on the second line. \$\endgroup\$ – cole Sep 25 '15 at 22:59
  • 1
    \$\begingroup\$ -1 byte if you move the o at end of the second line to the empty space at the start of the line, I believe. \$\endgroup\$ – Sp3000 Sep 26 '15 at 0:55
  • \$\begingroup\$ @Sp3000 Indeed, I spent so much time golfing this I don't know how this did not come to mind \$\endgroup\$ – Aaron Sep 27 '15 at 11:28
  • 1
    \$\begingroup\$ Who needs fizz buzz when you can have foooo Buzz? \$\endgroup\$ – caird coinheringaahing Sep 4 '17 at 20:46

gs2, 28 27 (without f)


1b 2f fe cc 04 46 69 7a 7a 09 07 42 75 7a 7a 19 06 27 2d d8 62 32 ec 99 dc 61 0a


1b    100
2f    range1 (1..n)
fe    m: (map rest of program)

cc    put0 (pop and store in register 0)
04    string-begin
09    9
07    string-separator
19    25
06    string-end-array (result: ["Fizz"+chr(9) "Buzz"+chr(25)])

27    right-uncons
2d    sqrt
d8    tuck0 (insert value of register 0 under top of stack)
62    divides
32    times (string multiplication)
ec    m5 (create block from previous 5 tokens, then call map)

99    flatten
dc    show0 (convert register 0 to string and push it)
61    logical-or
0a    newline

Embedding 3 and 5 into the string constant doesn't work because \x05 ends string literals.

Note: This problem can be solved in 1 byte with gs2 using the built-in f.


C, 85 bytes


-2 thanks to squeamish.

  • \$\begingroup\$ Trying to compile here but gcc doesnt recognize the new line inside the string as \n. It gives me a compiling error. Do I need to pass any parameter to the compiler? BTW, you missed the <= in your post (I counted 88 bytes with <= ... so im assuming it is missing). \$\endgroup\$ – wendelbsilva Sep 24 '15 at 20:57
  • \$\begingroup\$ oops. missed the error in the warnings. Adds 2 chars. \$\endgroup\$ – AShelly Sep 24 '15 at 21:01
  • \$\begingroup\$ Global variables are initialized to zero, so instead of main(i), try i;main(). Then you can get rid of the i-- at the start of the for() loop. You don't need the line break either. That should bring the byte count down to 85. \$\endgroup\$ – squeamish ossifrage Sep 24 '15 at 22:36
  • 2
    \$\begingroup\$ Depending on how UB you want to get, you can do 73, 74, or 75 bytes. Here's my 74 byte answer. \$\endgroup\$ – Lynn Sep 27 '15 at 16:44
  • 1
    \$\begingroup\$ OMG I spent maybe 3 hours trying to get this thing just one byte smaller. Here you go. Replace (i%3&&i%5)*i with i%3*i%5?i:0 I'm going to bed \$\endgroup\$ – Albert Renshaw Sep 30 '15 at 10:24

CJam, 35 bytes


Try it online in the CJam interpreter.

How it works

100{                             }/  For each integer I between 0 and 99:
    )_                                 Increment I and push a copy.
      [Z5]                             Push [3 5].
          f%                           Map % to push [(I+1)%3 (I+1)%5].
            :!                         Apply logical NOT to each remainder.
              "FizzBuzz"4/             Push ["Fizz" "Buzz"].
                          .*           Vectorized string repetition.
                            s\         Flatten the result and swap it with I+1.
                              e|       Logical OR; if `s' pushed an empty string,
                                       replace it with I+1.
                                N      Push a linefeed.
  • 3
    \$\begingroup\$ More straightforward solution: 100{):I3%!"Fizz"*I5%!"Buzz"*+Ie|N}/ \$\endgroup\$ – aditsu Sep 30 '15 at 14:12

MUMPS, 56 54 bytes

f i=1:1:100 w:i#5=0 "Fizz" w:i#3=0 "Buzz" w:$X<3 i w !

What's this w:$X<3 i thing, you ask? $X is a magic variable (an "intrinsic") that stores the horizontal position of the output cursor (as a number of characters from the left edge of the terminal). w is the abbreviated form of the WRITE command. The syntax command:condition args is a postconditional - "if condition, then do command args".

So we're checking whether the output cursor has been advanced more than two characters (which would mean that at least one of "Fizz" or "Buzz" has been written to the terminal), and if not, writing i to the terminal. The $X variable - and hence, this sort of deep inseparability from the terminal - is a first-class feature of MUMPS. Yikes.


Jelly, 24 20 bytes


Try it online!

How it works

³µ3,5ḍTị“¡Ṭ4“Ụp»ȯµ€G  Main link. No input.

³                     Yield 100.
 µ                    Begin a new, monadic chain.
                 µ€   Apply the preceding chain to all integers n in [1, ..., 100].
  3,5ḍ                Test n for divisibility by 3 and 5.
      T               Get all truthy indices.
                      This yields [1] (mult. of 3, not 5), [2] (mult. of 5, not 3),
                      [1, 2] (mult. of 15) or [].
        “¡Ṭ4“Ụp»      Yield ['Fizz', 'Buzz'] by indexing in a dictionary.
       ị              Retrieve the strings at the corr. indices.
                ȯ     Logical OR hook; replace an empty list with n.
                   G  Grid; join the list, separating by linefeeds.
  • \$\begingroup\$ again nobody out golfed dennis (except for the HQ9+ style answer) \$\endgroup\$ – noɥʇʎԀʎzɐɹƆ Jul 17 '16 at 17:08

brainfuck, 206 bytes



  <[>+< <<,<->>>+]

Try it online

The memory layout is

0 a 122 105 70 b f 0 t d1 s d2 c d 10 0

where f cycles by 3, b cycles by 5, d1 is ones digit, d2 is tens digit, s is a flag for whether to print tens digit, d cycles by 10, c is copy space for d, t is working space that holds 0 or junk data or a flag for not-divisible-by-3, and a determines program termination by offsetting the pointer after Buzz has been printed 20 times.


C#, 128 126 125 124 bytes

class A{static void Main(){for(var i=0;i++<100;)System.Console.Write("{0:#}{1:;;Fizz}{2:;;Buzz}\n",i%3*i%5>0?i:0,i%3,i%5);}}

89 bytes without the boilerplate code around.

Done with the use of C#'s conditional formatting.

With two section separators ;, Fizz or Buzz are printed if the value from their condition is zero.

Saved a total of 4 bytes thanks to @RubberDuck, @Timwi and @Riokmij.

  • \$\begingroup\$ It would be shorter to call Write and append the newline directly to the string, right? \$\endgroup\$ – RubberDuck Sep 24 '15 at 23:26
  • \$\begingroup\$ It’s also one byte shorter to write i%3*i%5>0?i:0 instead of i%3*i%5==0?0:i. \$\endgroup\$ – Timwi Sep 24 '15 at 23:31
  • \$\begingroup\$ You can save another byte on the for statement by using for(var i=0;i++<100;) \$\endgroup\$ – Najkin Sep 25 '15 at 8:08
  • 1
    \$\begingroup\$ You can save three more bytes by leveraging String Interpolation from C#6.0 and embedding the format arguments into the string itself (e.g. $"{(i%3*i%5>0?i:0):#}...\n") \$\endgroup\$ – LiamK Sep 29 '15 at 12:58
  • 1
    \$\begingroup\$ can do with 121 bytes today - class A{static void Main(){for(var i=0;i<100;)System.Console.Write($"{(++i%3*i%5<1?0:i):#}{i%3:;;Fizz}{i%5:;;Buzz}\n");}} \$\endgroup\$ – Jerri Kangasniemi Oct 28 '18 at 9:45

Clojure, 113 106 101 100 91 bytes

My first golf!

(dotimes[i 100](println(str({2'Fizz}(mod i 3))({4'Buzz}(mod i 5)({2""}(mod i 3)(inc i))))))


(dotimes [i 100] ; account for off-by-one later
  (println (str ({2 'Fizz} ; str converts symbols to strings
                 (mod i 3))
                ({4 'Buzz} ; 4 instead of 0 because of off-by-one
                 (mod i 5)
                 ({2 ""} ; shortest way to write when-not
                  (mod i 3)
                  (inc i))))))
  • 1
    \$\begingroup\$ You can remove 5 characters by handling the println the same way as in the Java solution, eg. (doall(map #(let[t(=(mod % 3)0)](println(str(if t"Fizz""")(if(=(mod % 5)0)"Buzz"(if t""%)))))(range 1 101))) \$\endgroup\$ – resueman Sep 25 '15 at 14:47
  • 1
    \$\begingroup\$ @resueman Thanks! It actually ended up being 7, because (if t"Fizz""") can be simplified to (if t"Fizz"). :) \$\endgroup\$ – Sam Estep Sep 25 '15 at 16:49
  • \$\begingroup\$ +1 Nice modulo trick, at first I though you had off-by-one errors. \$\endgroup\$ – coredump Sep 28 '15 at 8:09

PowerShell, 78 68 61 54 Bytes


Edit: Saved 10 bytes thanks to feersum

Edit2: Realized that with feersum's trick, I no longer need to formulate $t as a string-of-code-blocks

Edit3: Saved another 7 bytes thanks to Danko Durbić

Similar-ish in spirit to the stock Rosetta Code answer, but golfed down quite a bit.


1..100|%{...} Create a collection of 1 through 100, then for-each object in that collection, do

(...,$_) create a new collection of two elements: 0) $t=... set the variable $t equal to a string; 1) $_ our-current-number of the loop

"Fizz"*!($_%3) take our-current-number, mod it by 3, then NOT the result. Multiply "Fizz" by that, and add it to the string (and similar for 5). PowerShell treats any non-zero number as $TRUE, and thus the NOT of a non-zero number is 0, meaning that only if our-current-number is a multiple of 3 will "Fizz" get added to the string.

[!$t] indexes into the collection we just created, based on the value of the string $t -- non-empty, print it, else print our-current-number

Alternatively, also 54 bytes


Thanks to TesselatingHeckler

Similar in concept, this uses the inline -replace operator and a regular expression to swap out an empty string ^$ with our-current-number. If the string is non-empty, it doesn't get swapped.

Alternatively, also 54 bytes


This is the same loop structure as above, but inside it sorts the pair (n, string), and relies on the fact that an empty string sorts before a number, but a FizzBuzz string sorts after a number. Then it indexes the second sort result.

  • \$\begingroup\$ As an aside, if PowerShell ever implemented the || operator, like in C#, we could likely get down to 43 bytes with something similar to 1..100|%{"Fizz"*!($_%3)+"Buzz"*!($_%5)||$_} ... doubtful, since the | is such an important special operator in PowerShell, but I can dream ... \$\endgroup\$ – AdmBorkBork Sep 24 '15 at 20:51
  • 1
    \$\begingroup\$ How about 1..100|%{'Fizz'*!($_%3)+'Buzz'*!($_%5)-replace'^$',$_} for 54? \$\endgroup\$ – TessellatingHeckler Sep 25 '15 at 6:18
  • \$\begingroup\$ You can replace if($t){$t}else{$_} with something like ($t,$_)[!$t] \$\endgroup\$ – Danko Durbić Sep 25 '15 at 7:03
  • 1
    \$\begingroup\$ ... so you get 1..100|%{(($t="Fizz"*!($_%3)+"Buzz"*!($_%5)),$_)[!$t]} which is also 54 like @TessellatingHeckler's suggestion \$\endgroup\$ – Danko Durbić Sep 25 '15 at 8:01
  • \$\begingroup\$ @TessellatingHeckler PowerShell is nothing if not flexible. \$\endgroup\$ – AdmBorkBork Sep 26 '15 at 0:34

Scratch, 203 185 bytes

Bytes counted from the golfed textual representation, per this meta post. Scratch is not very space-efficient.

say is the closest thing to a stdout Scratch has: the sprite displays a speech bubble containing whatever it is saying. In practice, a wait n secs block would be needed to actually read this output, but for the purposes of this challenge this code fulfills the requirements.

  • \$\begingroup\$ You're missing numbers after the y = (in both occurrences) \$\endgroup\$ – Beta Decay Oct 28 '15 at 10:29
  • \$\begingroup\$ @BetaDecay Sorry? I don't follow. \$\endgroup\$ – timothymh Oct 28 '15 at 14:33
  • \$\begingroup\$ Inside the repeat loop, the set y to ... is missing a value \$\endgroup\$ – Beta Decay Oct 28 '15 at 17:04
  • 1
    \$\begingroup\$ @BetaDecay That's the empty string. :) if you click on the image, you can view it in action! \$\endgroup\$ – timothymh Oct 28 '15 at 17:12
  • 1
    \$\begingroup\$ Nice one. I've never seen a Scratch solution before. :) \$\endgroup\$ – HyperNeutrino Mar 7 '16 at 3:01

JavaScript, 62 bytes


I think I this is the shortest Javascript solution now.

  • \$\begingroup\$ Wow, just wow! But all the other JS answers use console.log; it's much less annoying than having to press "OK" on 100 pop-up boxes in a row. Could you please change this? It'll only be 62 bytes, still three better than mine. \$\endgroup\$ – ETHproductions Nov 15 '15 at 3:04
  • \$\begingroup\$ I'll have to do so tomorrow, as I have already edited 5 of my own posts and can't edit anymore... \$\endgroup\$ – Mama Fun Roll Nov 15 '15 at 5:16
  • 2
    \$\begingroup\$ Oh, I didn't realise there was a limit to editing... \$\endgroup\$ – ETHproductions Nov 15 '15 at 18:48

brainfuck, 411 350 277 258 bytes


  • -61 bytes by storing the values of "Fizz Buzz" as "BuziF" "BuziG" and redoing the number printing section.

  • -71 bytes by redoing the modulo number printing section, splitting the loop counter and the number counter, and reusing the newline cell as the mod value, among other things

  • -19 bytes by realising that there aren't any 0s in any FizzBuzz numbers. Also added explanation


Try it online!

Instead of checking if the number itself was divisible by 5 or 3 I had two counters keeping track of the modulo of the number, decrementing them for each number and printing out the corresponding word when they reached 0.

How It Works:

+[-[>+<<]>-]>--  Generate the number 61
[>+>++>++>++++++>+>>>++++++[<<<]>-] Set the tape to multiples of 61
TAPE: 0 0' 61  122 122 110 61  0 0 110
           "=" "z" "z" "n" "="
<+++++[>+>+>->>->++>>>-->>>++[<<<]>>>-]>[>]+++>> Modify values by multiples of 5
TAPE: 0' 5 66  117 122 105 71  3 0 100' 0 0 10
           "B" "u" "z" "i" "G"
Some info:
  5     - Buzz counter
  "Buz" - Buzz printing
  "ziG" - Fizz printing. Modifying the G in the loop is shorter than modifying it outside
  3     - Fizz counter
  0     - This is where the Fizz|Buzz check will be located
  100   - Loop counter
  0     - Number counter. It's not worth it to reuse the loop counter as this.
  0     - Sometimes a zero is just a zero
  10    - Value as a newline and to mod the number by

[ Loop 100 times
  >+<<<  Increment number counter
  -[<]<  Decrement Fizz counter
  [ If Fizz counter is 0
    >+++ Reset the Fizz counter to 3
    >+<< Set the Fizz|Buzz check to true
    -.+<.<.. Print "Fizz"
  [<]<] Sync pointers
  >>-[<<]> Decrement Buzz counter
  [ If Buzz counter is 0
    .>.>.. Print "Buzz"
    >>>>+  Set the Fizz|Buzz check to true
    [<]+++++< Reset the Buzz counter to 5
  >[>]>> Go to Fizz|Buzz check
  [ If there was no Fizz or Buzz for this number
    TAPE: 3% BuziG 5% 0 Loop Num' 0 10
    [->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]  Mod the number counter by 10
    TAPE: 3% BuziG 5% 0 Loop 0' Num 10-Num%10 Num%10 Num/10
    >[-<+>] Move Num back in place
    >,>[>]< Reset 10-Num%10
    [ For both Num/10 (if it exists) and Num%10
      >-[<+>-----]<--- Add 48 to the number to turn it into the ASCII equivilent
      .,< Print and remove
    ++++++++++> Add the 10 back
  <. Print the newline
  <<<<, Remove Fizz|Buzz check
  >- Decrement Loop counter
  • \$\begingroup\$ Well done Jo! I might try to beat that someday :) \$\endgroup\$ – Forcent Vintier Dec 15 '17 at 16:33

C, 74 bytes


The 0 argument to printf instead of "" is fishy, but seems to work on most platforms I try it on. puts segfaults when you try the same thing, though. Without it, you get 75 bytes.

There are 73-byte solutions that work on anarchy golf, and I found one digging around in the right places on the internet, but they rely on platform-specific behavior. (As you might have guessed, it's something of the form puts("Buzz"±...).)

  • \$\begingroup\$ Nice trick to get i=1 for the no args case (argc=1). It's a feature: you can start the sequence from any point by running ./fizzbuzz $(seq 40) :P \$\endgroup\$ – Peter Cordes May 27 '16 at 21:05

R, 88 83 77 71 70 bytes

I'm sure that this can be improved ... and it was with credit to @flodel. A further couple of bytes saved thanks to a suggestion from @njnnja and another from @J.Doe

  • \$\begingroup\$ A cat answer. The mouse is above :) \$\endgroup\$ – Silviu Burcea Sep 25 '15 at 10:36
  • 1
    \$\begingroup\$ I found a bit better: x=1:100;i=!x%%3;j=!x%%5;x[i]="Fizz";x[j]="Buzz";x[i&j]="FizzBuzz";cat(x,sep="\n") \$\endgroup\$ – flodel Sep 28 '15 at 2:13
  • \$\begingroup\$ @njnnja Thanks for the suggestion. I implemented it with a write rather than cat though \$\endgroup\$ – MickyT Sep 28 '15 at 19:07
  • 2
    \$\begingroup\$ Necromancy here! The write call can take a 1 instead of a an empty string so x=y=1:100;y[3*x]='Fizz';y[5*x]='Buzz';y[15*x]='FizzBuzz';write(y[x],1) is a trivial 1 byte golf for 70 bytes. \$\endgroup\$ – J.Doe Oct 1 '18 at 13:00
  • \$\begingroup\$ 68 bytes. The bytecount includes three unprintable backspaces, and it doesn't work correctly in TIO. \$\endgroup\$ – J.Doe Oct 4 '18 at 21:41

Haskell, 84 bytes

main=mapM f[1..100]
f n|d<-drop.(*4).mod n=putStrLn$max(show n)$d 3"Fizz"++d 5"Buzz"

Getting close to henkma's 81 bytes, but not quite there yet.

d = drop.(*4).mod n is key here: d 3 "Fizz" is drop (n`mod`3 * 4) "Fizz". This is "Fizz" when n `mod` 3 is 0 and "" otherwise.

  • \$\begingroup\$ Rearrangement golfs it down to 82, I think: (%)=drop.(*4).mod n;main=mapM putStrLn[max(show n)$3%"Fizz"++5%"Buzz"|n<-[0..100]]. \$\endgroup\$ – CR Drost Sep 27 '15 at 16:35
  • \$\begingroup\$ Wait, then n isn't in scope. Hm. \$\endgroup\$ – CR Drost Sep 27 '15 at 16:38
  • \$\begingroup\$ Yeah, that doesn't work, but I've hit an alternative 85-byte solution that looks a lot like it: main=mapM putStrLn[max(show n)$3%"Fizz"++5%"Buzz"|n<-[0..100],(%)<-[drop.(*4).mod n]] \$\endgroup\$ – Lynn Sep 28 '15 at 22:47
  • \$\begingroup\$ Why not use a line break? It's just as short as a semicolon but less unreadable. \$\endgroup\$ – dfeuer Feb 28 at 3:00
  • 1
    \$\begingroup\$ I suggest you reconsider your quest for readable code on a code golf website :) \$\endgroup\$ – Lynn Feb 28 at 22:25

PHP, 54 bytes


Valid for v5.5 onwards. The õ is character 245, a bit inverted \n.

I assume the default interpreter settings, as they are without any ini. If you are uncertain, you may disable your local ini with -n as in php -n fizzbuzz.php.

A version which will run error-free with absolutely any configuration file is 62 bytes:

  • \$\begingroup\$ The STFU operator @ does not necessarily mean that the code is error free. \$\endgroup\$ – sitilge Sep 28 '15 at 12:42
  • \$\begingroup\$ ideone.com/5rfNt0 \$\endgroup\$ – Kzqai Sep 30 '15 at 6:55
  • \$\begingroup\$ @Kzqai ideone.com/0zRA9e short_open_tag is off, E_NOTICE is on. Neither of these are default settings. \$\endgroup\$ – primo Sep 30 '15 at 11:46
  • \$\begingroup\$ I'm getting a bunch of errors on 3v4l.org \$\endgroup\$ – a coder Jan 27 '16 at 23:42
  • \$\begingroup\$ @acoder relevant meta post. 3v4l.org seems useful. \$\endgroup\$ – primo Jan 28 '16 at 9:32

80386 machine code + DOS, 75 bytes

Hexdump of the code:

0D 0A 24 B1 64 33 C0 BA-03 05 BB 00 01 40 50 FE
CE 75 0C 83 EB 04 66 C7-07 42 75 7A 7A B6 05 FE
CA 75 0C 83 EB 04 66 C7-07 46 69 7A 7A B2 03 84
FF 74 0C D4 0A 04 30 4B-88 07 C1 E8 08 75 F4 52
8B D3 B4 09 CD 21 5A 58-E2 C0 C3

Source code (TASM syntax):


    org 100h

    db 13, 10, '$'
    mov cl, 100
    xor ax, ax
    mov dx, 503h

    mov bx, 100h
    inc ax
    push ax

    dec dh
    jnz short buzz_done
    sub bx, 4
    mov dword ptr [bx], 'zzuB'
    mov dh, 5

    dec dl
    jnz short fizz_done
    sub bx, 4
    mov dword ptr [bx], 'zziF'
    mov dl, 3

    test bh, bh
    jz short num_done

    add al, '0'
    dec bx
    mov [bx], al
    shr ax, 8
    jnz decimal_loop

    push dx
    mov dx, bx;
    mov ah, 9
    int 21h
    pop dx
    pop ax

    loop main_loop


This code counts from 1 to 100 in ax, building the output message from the end to the beginning. The end of the message (newline and the $ character that DOS uses for end-of-message flag) appears at the beginning of the code:

db 10, 10, '$'

It's executed as a harmless instruction (or ax, 240ah). I could put it in a more conventional place, like after the end of the code, but having it at address 0x100 has a benefit.

The code also uses 2 additional counters:

  • Counting from 3 to 0 in dl
  • Counting from 5 to 0 in dh

When a counter reaches 0, it pushes the string Fizz or Buzz to the end of the output message. If this happens, bx will be decreased, and bh will be zero. This is used as a condition for outputting the number in a decimal form.

Note: I am using 32-bit data here. This won't work on a pre-386 computer.

  • \$\begingroup\$ Does TASM really handle multi-byte characters constants in the opposite order from NASM? In NASM, you write mov [mem], 'Fizz' to store Fizz in that order in memory, matching db directives. See my overcomplicated "efficient" YASM FizzBuzz for example. \$\endgroup\$ – Peter Cordes May 28 '16 at 0:36
  • 1
    \$\begingroup\$ Does it save any bytes to use std, then stosb / stosd? You'd have to replace test bh,bh with cmp di, 100h or something. Instead of saving/restoring the counter in AL, you could keep it in BL and just clobber eax whenever you want. E.g. sub bx, 4 / mov dword ptr [bx], 'zzuB' is 3+7 bytes, right? mov eax, 'zzuB' / stosd is 6+2 bytes (operand-size prefix on both). It would be nice if the answer included disassembly so instruction sizes were visible. \$\endgroup\$ – Peter Cordes May 28 '16 at 0:46
  • 1
    \$\begingroup\$ This is a great answer - abusing benign instructions for data and using never-used PSP memory space. @PeterCordes I played with your suggestions using stosd but wasn't able to eek out any score reduction myself. Since stosd decrements DI afterwards you don't get to lose the sub di, 4 and then you have DI 4 bytes off at the end. I was able to -6 bytes using a few other minor tweaks which I ended up posting as a separate answer (only because I couldn't possibly fit in all a comment). Kudos! \$\endgroup\$ – 640KB Aug 27 at 17:19

dc, 64 62 bytes



[[Fizz]P]sI  # macro I: print "Fizz"
[[Buzz]P]sU  # macro U: print "Buzz"
[dn]sN       # macro N: print current stack depth

z            # increase stack depth

[            # Begin macro
  zdd           # Get current stack depth and ducplicate it twice
  3%d0=I        # Check modulo 3 and leave a duplicate. If it's 0, run macro I
  r             # Rotate top two elements, bringing up the stack depth again
  5%d0=U        # Check modulo 5 and leave a duplicate. It it's 0, run macro U
  *             # Multiply the duplicates of modulos of 3 and 5 ...
  0<N           # ... if it's not 0, run macro N
  AP            # Print a newline (`A` is 10)
                # The macro leaves the stack with one more element each time
  z9B>L      # Run macro L if stack depth is less than "ninety eleven" (101)
]         # End macro

dsLx  # store the macro in register L and execute it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.