1, 2, Fizz, 4, Buzz

152

39

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.

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

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>

Beta Decay

Posted 2015-09-24T19:23:54.480

Reputation: 21 478

1Nothing can be printed to STDERR. Is this true only when running, or also when compiling (assuming that is a separate step?) – AShelly – 2015-09-24T20:47:43.363

@AShelly Only when running – Beta Decay – 2015-09-24T20:48:06.640

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. – Timwi – 2015-09-24T23:28:17.400

8@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. – Geobits – 2015-09-25T00:50:36.917

TI-BASIC's Disp outputs strings left-justified and numbers right-justified. Is that acceptable? – lirtosiast – 2015-09-25T03:54:16.040

@ThomasKwa Yes, I would think so – Beta Decay – 2015-09-25T05:47:32.010

61A "vanilla fizzbuzz" sounds delicious. – Reinstate Monica -- notmaynard – 2015-09-25T15:12:09.853

QBasic outputs numbers with a leading space. Is that acceptable? (Workaround costs 14 bytes.) – DLosc – 2015-09-27T21:27:58.193

What is that code snippet at the end of your answer? Is it automatically scrapping the page for answers? – David says Reinstate Monica – 2015-09-28T17:44:08.520

@DavidGrinberg Yep, it gets the answers and puts them into the leaderboard :) – Beta Decay – 2015-09-28T17:45:21.783

I can always add my Shakespearian reply, but since it barely counts as a "golfed code" (and SPL is nearly impossible to golf), perhaps it's best not to.

– Rodolfo Dias – 2015-12-03T12:19:14.723

Answers

82

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:

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

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!

M L

Posted 2015-09-24T19:23:54.480

Reputation: 2 865

1Very 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.) – Martin Ender – 2016-03-06T09:45:08.770

@MartinBüttner I would love to see it :) – M L – 2016-03-06T16:56:44.507

2I am less of a programmer than you, because what is Visual Studio? :P – Rɪᴋᴇʀ – 2016-03-10T02:42:22.240

5Unfortunately EsotericIDE can’t do that automatically. — Please go right ahead and file a feature suggestion, I might get around to doing that some day :) – Timwi – 2016-03-10T13:22:07.093

1(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 – Sunny Pun – 2016-10-14T03:50:57.843

76

Python 2, 56

i=0;exec"print i%3/2*'Fizz'+i%5/4*'Buzz'or-~i;i+=1;"*100

feersum

Posted 2015-09-24T19:23:54.480

Reputation: 29 566

6Dang, that's bloody genius. Can I steal your idea to multiply the string by the mod-result? – AdmBorkBork – 2015-09-24T20:01:15.500

@TimmyD Go ahead. – feersum – 2015-09-24T20:06:59.743

16

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?

– xnor – 2015-09-25T05:35:22.123

@ETHproductions It does.

– Ben Fortune – 2015-09-25T09:50:36.227

May I also steal your mod trick for a Ruby answer? – Reinstate Monica -- notmaynard – 2015-09-25T15:39:36.577

1Very 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) ;) – Tersosauros – 2016-03-06T13:09:57.500

2@Tersosauros Go ahead... my method is not very hard to find and has no doubt been independently discovered by many people. – feersum – 2016-03-06T21:16:54.057

@MickyT What? That's 91 bytes long and not even valid, as it would only work in a REPL. – feersum – 2016-03-17T04:00:32.467

45

Labyrinth, 94 bytes

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

Sub-100! This was a fun one.

Explanation

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

Red

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.

Purple

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.

Sp3000

Posted 2015-09-24T19:23:54.480

Reputation: 58 729

7Loving the explanation. – The_Basset_Hound – 2015-09-27T23:08:33.557

29

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

Dom Hastings

Posted 2015-09-24T19:23:54.480

Reputation: 16 415

You can save a few bytes by using say. – Dennis – 2015-09-25T06:15:12.930

You broke the scoreboard... – LegionMammal978 – 2015-09-27T12:10:51.147

@LegionMammal978 Yes. Yes I did... I'll try and re-word the title then! Argh! – Dom Hastings – 2015-09-27T12:47:19.677

Isn't -E"..." 8 bytes? Space + Dash + Option + Argument (+ Quoting). – Erik the Outgolfer – 2016-09-22T11:00:08.873

1

@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: http://meta.codegolf.stackexchange.com/a/7539

– Dom Hastings – 2016-09-22T11:30:49.483

27

Ruby, 50 bytes

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

1.upto(?d){|n|puts'FizzBuzz
'[i=n**4%-15,i+13]||n}

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

This seems to be the world record.

Lynn

Posted 2015-09-24T19:23:54.480

Reputation: 55 648

1That is diabolical, love it. – Camden Narzt – 2015-09-28T01:13:52.683

?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. – Lynn – 2015-09-30T21:34:48.687

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. – Shelvacu – 2015-11-12T06:11:39.590

Can you explain the [i=n**4%-15,i+13] part please? Can't seem to wrap my head around it – Piccolo – 2018-08-04T23:02:13.383

2

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

– Lynn – 2018-08-04T23:15:58.330

@Lynn Oh, that's really neat! Thank you! – Piccolo – 2018-08-05T02:07:50.623

26

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));}}

Geobits

Posted 2015-09-24T19:23:54.480

Reputation: 19 061

I don't think the initializer block trick helps here, since the question specifies empty stderr. – feersum – 2015-09-24T19:47:50.133

Hmm. I know the static trick prints to stderr, but I thought enum ran cleanly. Good to know :) – Geobits – 2015-09-24T19:49:06.027

@Geobits I have created a Processing answer based of your Java answer. – user41805 – 2015-09-24T20:22:09.203

4beat me by 14 bytes! Using <1 instead of ==0 is a great way to save! – ESP – 2015-11-08T18:25:46.097

2class F{public static -> interface F{static in java 8 – TheNumberOne – 2015-11-28T15:53:47.290

1That's not quite how enums work. You would have to do enum F{;public..., so you wouldn't actually be saving any bytes. – HyperNeutrino – 2016-03-07T02:56:35.727

But great job! +1 – HyperNeutrino – 2016-03-07T02:58:50.337

@HyperNeutrino The enum trick works if you add System.exit(0); at the end. Total length: 112 bytes. enum F{F;{for(int i=0;i++<100;)System.out.println((i%3<1?"Fizz":"")+(i%5<1?"Buzz":i%3<1?"":i));System.exit(0);}}. See my "Hello World" answer for details.

– Olivier Grégoire – 2017-11-23T17:48:36.090

23

Pyth, 30

VS100|+*!%N3"Fizz"*!%N5"Buzz"N

Try it here

Explanation:

VS100|+*!%N3"Fizz"*!%N5"Buzz"N
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

FryAmTheEggman

Posted 2015-09-24T19:23:54.480

Reputation: 16 206

23

Retina, 317 139 134 132 70 63 60 55 bytes

.100{`^
_
*\(a`(___)+
Fi;$&
\b(_{5})+$
Bu;
;_*
zz
'_&`.

Try it online!

Explanation

.100{`^
_

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.

*\(a`(___)+
Fi;$&

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.

\b(_{5})+$
Bu;

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

_
__
Fi;___
____
Bu;
Fi;______
...
Fi;Bu;
...

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

;_*
zz

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.

Martin Ender

Posted 2015-09-24T19:23:54.480

Reputation: 184 808

22

gs2, 1

f

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.

Mitch Schwartz

Posted 2015-09-24T19:23:54.480

Reputation: 4 899

20

Perl 5, 45 bytes

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

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.

primo

Posted 2015-09-24T19:23:54.480

Reputation: 30 891

You can use say, with the -E switch, which has edit distance 1 to -e, so it should count as 1 byte. – Dennis – 2015-09-25T06:24:24.970

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?

– Dom Hastings – 2015-09-25T16:15:50.530

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. – primo – 2015-09-25T16:39:16.497

20

beeswax, 104 89 81 bytes

Denser packing allowed for cutting off 8 more bytes.

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

p?@<
p?{@b'gA<
p@`zzuB`d'%~5F@<f`z`<
 >~P"#"_"1F3~%'d`Fiz`b
 d;"-~@~.<
>?N@9P~0+d

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
d`Fizz`f>

into

<f`z`<
d`Fiz`b

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      <
p?<@`zzuB`b'%~5F@<f`zziF`b'<
>N@9P~0+.~@~-";~P"#"_"1F3~%d

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

M L

Posted 2015-09-24T19:23:54.480

Reputation: 2 865

2This is as crazy and beautiful as Hexagony. Have a +1! – ETHproductions – 2016-02-26T17:08:59.133

@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. – M L – 2016-02-26T17:17:50.660

Let us continue this discussion in chat.

– M L – 2016-12-03T20:53:54.300

How are you making those animations? – baordog – 2018-08-19T03:32:04.540

18

><>, 68 66 65 64 bytes

1\2+2foooo "Buzz"<
o>:::3%:?!\$5%:?!/*?n1+:aa*)?;a
o.!o"Fizz"/oo

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!

Aaron

Posted 2015-09-24T19:23:54.480

Reputation: 3 689

1Very well golfed, I love the reuse of the "" on the first line and the one on the second line. – cole – 2015-09-25T22:59:03.020

1-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. – Sp3000 – 2015-09-26T00:55:33.183

@Sp3000 Indeed, I spent so much time golfing this I don't know how this did not come to mind – Aaron – 2015-09-27T11:28:10.223

1Who needs fizz buzz when you can have foooo Buzz? – caird coinheringaahing – 2017-09-04T20:46:17.337

17

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.

senshin

Posted 2015-09-24T19:23:54.480

Reputation: 641

17

gs2, 28 27 (without f)

Hex:

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

Explanation:

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

cc    put0 (pop and store in register 0)
04    string-begin
Fizz
09    9
07    string-separator
Buzz
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.

Mitch Schwartz

Posted 2015-09-24T19:23:54.480

Reputation: 4 899

16

CJam, 35 bytes

100{)_[Z5]f%:!"FizzBuzz"4/.*s\e|N}/

Try it online in the CJam interpreter.

How it works

100{)_[Z5]f%:!"FizzBuzz"4/.*s\e|N}/
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.

Dennis

Posted 2015-09-24T19:23:54.480

Reputation: 196 637

3More straightforward solution: 100{):I3%!"Fizz"*I5%!"Buzz"*+Ie|N}/ – aditsu quit because SE is EVIL – 2015-09-30T14:12:31.137

16

C, 85 bytes

i;main(){for(;i++<=99;printf("%s%s%.d\n",i%3?"":"Fizz",i%5?"":"Buzz",(i%3&&i%5)*i));}

-2 thanks to squeamish.

AShelly

Posted 2015-09-24T19:23:54.480

Reputation: 4 281

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). – wendelbsilva – 2015-09-24T20:57:37.627

1oops. missed the error in the warnings. Adds 2 chars. – AShelly – 2015-09-24T21:01:54.840

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. – r3mainer – 2015-09-24T22:36:52.350

Thanks. (I wasn't counting the newline, just inserted for readability.) – AShelly – 2015-09-24T22:44:54.667

Found a way to shave one more byte: main(i){for(;printf("%s%s%.d\n",i%3?"":"Fizz",i%5?"":"Buzz",(i%3&&i%5)*i),99/i++;);} – Tob Ernack – 2015-09-25T04:48:11.957

So it should be 84 bytes now. (I wanted to add this to my other comment but edit timed out) – Tob Ernack – 2015-09-25T04:58:00.623

printf(i%5?i%3?"%d\n":"Fizz\n":i%3?"Buzz\n":"FizzBuzz\n",i) saves another byte, can be combined with @TobErnack's comment. – hvd – 2015-09-26T16:58:07.293

2

Depending on how UB you want to get, you can do 73, 74, or 75 bytes. Here's my 74 byte answer.

– Lynn – 2015-09-27T16:44:44.740

Feel like there is something you can do with the double "zz" in fizz and buzz haha – Albert Renshaw – 2015-09-30T05:34:03.997

1OMG 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 – Albert Renshaw – 2015-09-30T10:24:59.053

15

brainfuck, 206 bytes

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

Formatted:

++>+++++>>>>>
++++++++++[>+>>+>>+>+<<<[++++<-<]<,<,-<-<++<++++[<++>++++++>]++>>]
>
[
  +
  [
    [<<]
    <[>>]
    +++<
    [
      Fizz
      <.<.<..
      [>]
    ]
    <<-
    [
      >>>
      [
        ,>>[<]
        >[--.++<<]
        >
      ]
    ]
    +++++<
    [
      Buzz
      +[-----.++++<<]
      >>+..
      <-
      [>]
    ]
    <[->>,>+>>>->->.>]
    <<
  ]
  <[>+< <<,<->>>+]
  <
]

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.

Mitch Schwartz

Posted 2015-09-24T19:23:54.480

Reputation: 4 899

15

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.

timothymh

Posted 2015-09-24T19:23:54.480

Reputation: 379

You're missing numbers after the y = (in both occurrences) – Beta Decay – 2015-10-28T10:29:12.577

@BetaDecay Sorry? I don't follow. – timothymh – 2015-10-28T14:33:08.583

Inside the repeat loop, the set y to ... is missing a value – Beta Decay – 2015-10-28T17:04:57.353

1@BetaDecay That's the empty string. :) if you click on the image, you can view it in action! – timothymh – 2015-10-28T17:12:16.043

Ohhh haha sorry for doubting you ;) – Beta Decay – 2015-10-28T17:22:04.540

1Nice one. I've never seen a Scratch solution before. :) – HyperNeutrino – 2016-03-07T03:01:07.637

15

Jelly, 24 20 bytes

³µ3,5ḍTị“¡Ṭ4“Ụp»ȯµ€G

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.

Dennis

Posted 2015-09-24T19:23:54.480

Reputation: 196 637

again nobody out golfed dennis (except for the HQ9+ style answer) – noɥʇʎԀʎzɐɹƆ – 2016-07-17T17:08:30.233

14

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.

Pierre-Luc Pineault

Posted 2015-09-24T19:23:54.480

Reputation: 331

It would be shorter to call Write and append the newline directly to the string, right? – RubberDuck – 2015-09-24T23:26:31.107

It’s also one byte shorter to write i%3*i%5>0?i:0 instead of i%3*i%5==0?0:i. – Timwi – 2015-09-24T23:31:25.057

You can save another byte on the for statement by using for(var i=0;i++<100;) – Najkin – 2015-09-25T08:08:34.250

@LegionMammal978 No, it cannot, it would hide the i only on multiple of 15, instead of 3, 5 and 15.. You can try it. – Pierre-Luc Pineault – 2015-09-26T03:07:52.917

This skips number 1. Start form i=0. – Hand-E-Food – 2015-09-28T01:01:53.103

@Hand-E-Food Oh, indeed! I forgot to change that part while doing the improvement suggested by Riokmij. Thanks! – Pierre-Luc Pineault – 2015-09-28T01:52:52.430

1

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")

– LiamK – 2015-09-29T12:58:53.043

Live code for this http://csharppad.com/gist/c235498d6c042476664420a1b5ab0e7b

– Tim Abell – 2017-03-19T22:44:48.297

1can 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");}} – Jerri Kangasniemi – 2018-10-28T09:45:53.200

14

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

Ungolfed:

(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))))))

Sam Estep

Posted 2015-09-24T19:23:54.480

Reputation: 251

1

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

– resueman – 2015-09-25T14:47:38.103

1@resueman Thanks! It actually ended up being 7, because (if t"Fizz""") can be simplified to (if t"Fizz"). :) – Sam Estep – 2015-09-25T16:49:29.037

+1 Nice modulo trick, at first I though you had off-by-one errors. – coredump – 2015-09-28T08:09:37.853

13

brainfuck, 411 350 277 258 bytes

Edits:

  • -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
]

Jo King

Posted 2015-09-24T19:23:54.480

Reputation: 38 234

Well done Jo! I might try to beat that someday :) – Forcent Vintier – 2017-12-15T16:33:17.673

13

PowerShell, 78 68 61 54 Bytes

1..100|%{(($t="Fizz"*!($_%3)+"Buzz"*!($_%5)),$_)[!$t]}

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.

Explanation

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

1..100|%{'Fizz'*!($_%3)+'Buzz'*!($_%5)-replace'^$',$_}

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

1..100|%{($_,('Fizz'*!($_%3)+'Buzz'*!($_%5))|sort)[1]}

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.

AdmBorkBork

Posted 2015-09-24T19:23:54.480

Reputation: 41 581

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 ... – AdmBorkBork – 2015-09-24T20:51:06.303

1How about 1..100|%{'Fizz'*!($_%3)+'Buzz'*!($_%5)-replace'^$',$_} for 54? – TessellatingHeckler – 2015-09-25T06:18:09.777

You can replace if($t){$t}else{$_} with something like ($t,$_)[!$t] – Danko Durbić – 2015-09-25T07:03:23.873

1... so you get 1..100|%{(($t="Fizz"*!($_%3)+"Buzz"*!($_%5)),$_)[!$t]} which is also 54 like @TessellatingHeckler's suggestion – Danko Durbić – 2015-09-25T08:01:45.883

@TessellatingHeckler PowerShell is nothing if not flexible. – AdmBorkBork – 2015-09-26T00:34:16.407

13

C, 74 bytes

main(i){for(;i<101;puts(i++%5?"":"Buzz"))printf(i%3?i%5?"%d":0:"Fizz",i);}

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"±...).)

Lynn

Posted 2015-09-24T19:23:54.480

Reputation: 55 648

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 – Peter Cordes – 2016-05-27T21:05:47.257

13

JavaScript, 62 bytes

for(i=0;++i<101;console.log(i%5?f||i:f+'Buzz'))f=i%3?'':'Fizz'

I think I this is the shortest Javascript solution now.

Mama Fun Roll

Posted 2015-09-24T19:23:54.480

Reputation: 7 234

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. – ETHproductions – 2015-11-15T03:04:02.363

I'll have to do so tomorrow, as I have already edited 5 of my own posts and can't edit anymore... – Mama Fun Roll – 2015-11-15T05:16:36.000

2Oh, I didn't realise there was a limit to editing... – ETHproductions – 2015-11-15T18:48:42.617

13

ArnoldC, 842 bytes

IT'S SHOWTIME
HEY CHRISTMAS TREE a
YOU SET US UP 100
HEY CHRISTMAS TREE b
YOU SET US UP 0
HEY CHRISTMAS TREE r
YOU SET US UP 0
STICK AROUND a
GET TO THE CHOPPER b
HERE IS MY INVITATION 101
GET DOWN a
ENOUGH TALK
GET TO THE CHOPPER r
HERE IS MY INVITATION b
I LET HIM GO 15
ENOUGH TALK
BECAUSE I'M GOING TO SAY PLEASE r
GET TO THE CHOPPER r
HERE IS MY INVITATION b
I LET HIM GO 3
ENOUGH TALK
BECAUSE I'M GOING TO SAY PLEASE r
GET TO THE CHOPPER r
HERE IS MY INVITATION b
I LET HIM GO 5
ENOUGH TALK
BECAUSE I'M GOING TO SAY PLEASE r
TALK TO THE HAND b
BULLSHIT
TALK TO THE HAND "Buzz"
YOU HAVE NO RESPECT FOR LOGIC
BULLSHIT
TALK TO THE HAND "Fizz"
YOU HAVE NO RESPECT FOR LOGIC
BULLSHIT
TALK TO THE HAND "FizzBuzz"
YOU HAVE NO RESPECT FOR LOGIC
GET TO THE CHOPPER a
HERE IS MY INVITATION a
GET DOWN 1
ENOUGH TALK
CHILL
YOU HAVE BEEN TERMINATED

First try at golfing, I think this is as bad as it gets (both language and golfing).

drolex

Posted 2015-09-24T19:23:54.480

Reputation: 290

1YOU HAVE NO RESPECT FOR LOGIC lol, this is a great language ;) – ETHproductions – 2016-03-10T17:39:14.033

1Hahahaha!!! You should've made it a method, worse bytecount, better phrases ;). – Magic Octopus Urn – 2016-10-13T17:46:32.550

12

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

x=y=1:100;y[3*x]='Fizz';y[5*x]='Buzz';y[15*x]='FizzBuzz';write(y[x],1)

MickyT

Posted 2015-09-24T19:23:54.480

Reputation: 11 735

A cat answer. The mouse is above :) – Silviu Burcea – 2015-09-25T10:36:36.717

1I 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") – flodel – 2015-09-28T02:13:07.413

@njnnja Thanks for the suggestion. I implemented it with a write rather than cat though – MickyT – 2015-09-28T19:07:47.657

2Necromancy 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. – J.Doe – 2018-10-01T13:00:26.300

68 bytes. The bytecount includes three unprintable backspaces, and it doesn't work correctly in TIO. – J.Doe – 2018-10-04T21:41:27.850

@J.Doe I like the use of backspaces in this, but I think it may not be acceptable based on this meta and the statement in the rules " ... Because the output is fixed ... ". Still nice job

– MickyT – 2018-10-04T21:56:26.790

Oh well, it was worth a try! If escape characters are disallowed in this kind of challenge, then I guess 70 bytes is rock bottom. – J.Doe – 2018-10-04T22:26:33.307

12

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.

Lynn

Posted 2015-09-24T19:23:54.480

Reputation: 55 648

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]]. – CR Drost – 2015-09-27T16:35:52.547

Wait, then n isn't in scope. Hm. – CR Drost – 2015-09-27T16:38:16.257

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]] – Lynn – 2015-09-28T22:47:18.830

Why not use a line break? It's just as short as a semicolon but less unreadable. – dfeuer – 2019-02-28T03:00:08.097

@dfeuer I remember I was trying lots of different FizzBuzz approaches, and I wrote them all as one-liners in a single file to easily compare their lengths. – Lynn – 2019-02-28T14:23:33.173

Could you change it now? Horizontal scrolling is especially rough on mobile devices. – dfeuer – 2019-02-28T20:03:54.790

1I suggest you reconsider your quest for readable code on a code golf website :) – Lynn – 2019-02-28T22:25:52.333

Whoops.... That down vote was mine, and entirely accidental. – dfeuer – 2019-03-23T21:05:39.427

11

Bubblegum, 131 129 bytes

0000000: 4d cd bb 0d c4 30 0c 03 d0 9e db e8 63 7d da 14 d9 e5  M....0......c}....
0000012: 06 b8 26 d3 e7 60 0b 38 56 a6 29 10 4f a0 b8 3f cf 03  ..&..`.8V.).O..?..
0000024: c7 f5 fd 3d 3b 27 ea 84 5d 89 9c 8f 18 c4 77 3c 75 40  ...=;'..].....w<u@
0000036: 72 2e 4d 63 55 a8 d1 5c 63 fa 82 f6 7f 6e 02 1b da d8  r.McU..\c....n....
0000048: b6 84 b1 ee a3 bb c1 49 f7 80 8f ee ac 2f c5 62 7d 8d  .......I...../.b}.
000005a: be 0a 8b f4 10 c4 e8 c1 7a 24 82 f5 1c 3d 0d 49 7a 06  ........z$...=.Iz.
000006c: 72 f4 64 bd 14 c5 7a 8d 5e 85 22 bd 05 3d 7a b3 de 89  r.d...z.^."..=z...
000007e: 26 fd 05                                               &..

The above hexdump can be reversed with xxd -r -c 18 > fizzbuzz.bg.

Compression has been done with Python's zlib, which uses the DEFLATE format but obtains a better ratio than (g)zip.

Thanks to @Sp3000 for -2 bytes!

Dennis

Posted 2015-09-24T19:23:54.480

Reputation: 196 637

27You could golf off about 43 bytes by breaking SHA-256. – lirtosiast – 2015-09-25T00:07:00.903

1@ThomasKwa: sounds easy. – ceased to turn counterclockwis – 2015-09-25T22:41:23.443

11

dc, 64 62 bytes

[[Fizz]P]sI[[Buzz]P]sU[dn]sNz[zdd3%d0=Ir5%d0=U*0<NAPz9B>L]dsLx

Ungolfed:

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

daniero

Posted 2015-09-24T19:23:54.480

Reputation: 17 193

11

PHP, 54 bytes

<?for(;$i++<100;)echo[Fizz][$i%3].[Buzz][$i%5]?:$i,~õ;

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:

<?php
for(;$i++<100;)echo@([Fizz][$i%3].[Buzz][$i%5]?:$i),"
";

primo

Posted 2015-09-24T19:23:54.480

Reputation: 30 891

The STFU operator @ does not necessarily mean that the code is error free. – sitilge – 2015-09-28T12:42:47.973

https://ideone.com/5rfNt0 – Kzqai – 2015-09-30T06:55:07.040

@Kzqai http://ideone.com/0zRA9e short_open_tag is off, E_NOTICE is on. Neither of these are default settings.

– primo – 2015-09-30T11:46:47.927

I'm getting a bunch of errors on 3v4l.org – a coder – 2016-01-27T23:42:43.063

@acoder relevant meta post. 3v4l.org seems useful.

– primo – 2016-01-28T09:32:15.337

Save two bytes: use -r and remove the tag. – Titus – 2017-02-11T17:27:54.017

@Titus From the description: "Write a program." I understand that many people in this community have chosen to willfully misinterpret this. – primo – 2017-02-11T19:20:59.103

11

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):

    .MODEL TINY

    .CODE
    .386
    org 100h

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

main_loop:
    mov bx, 100h
    inc ax
    push ax

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

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

    test bh, bh
    jz short num_done

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

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

    loop main_loop
    ret

MAIN ENDP
    END MAIN

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.

anatolyg

Posted 2015-09-24T19:23:54.480

Reputation: 10 719

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.

– Peter Cordes – 2016-05-28T00:36:34.410

1Does 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. – Peter Cordes – 2016-05-28T00:46:30.307

1

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!

– 640KB – 2019-08-27T17:19:33.157

11

Lua, 72 bytes

for i=1,100 do print(({'FizzBuzz','Buzz','Fizz',i})[i^2%3+i^4%5*2+1])end

Tied the world record! (Please don't cheat the rankings there.)

Lynn

Posted 2015-09-24T19:23:54.480

Reputation: 55 648

I stole this technique for my AppleScript answer.

– kernigh – 2017-10-25T02:38:30.833

2Cool answer. My 72 was for x=1,100 do print(({x,[0]="FizzBuzz",[6]="Fizz"})[x^4%15]or"Buzz")end, but looking at yours, I saw this 70: for x=1,100 do print(({"FizzBuzz",x,[7]="Fizz"})[1+x^4%15]or"Buzz")end – tehtmi – 2018-07-18T23:34:06.710

@tehtmi Oh, that’s so nifty! – Lynn – 2018-07-21T15:34:13.840

10

Hexagony, 112 bytes

d{$>){*./;\.}<._.zi...><{}.;/;$@-/=.*F;>8M'<$<..'_}....>.3'%<}'>}))'%<..._>_.'<$.....};u..}....{B.;..;.!<'..>z;/

After unfolding and with colour-coded execution paths:

enter image description here
Diagram created with Timwi's HexagonyColorer.

Finally got around to finishing this. I had written an ungolfed solution weeks ago, but wasn't entirely happy with it so I never actually golfed it. After revisiting it the other day, I found a way to simplify the ungolfed solution slightly, and while I think there might still be a better way to approach the problem in general, I decided to golf it this time. The current solution is far from optimal, and I think it should actually fit in side-length 6 instead of 7. I'll give this a go over the next days, and when I'm happy with the result will add a full explanation.

Martin Ender

Posted 2015-09-24T19:23:54.480

Reputation: 184 808

1That execution is a mess :P – LegionMammal978 – 2015-11-08T21:12:26.033

@LegionMammal978 I've seen worse. ;)

– Martin Ender – 2015-11-08T21:13:39.000

How do you create those diagrams? – LegionMammal978 – 2015-11-08T21:18:21.760

@LegionMammal978 Oh, I forgot to add the usual credits: https://github.com/Timwi/HexagonyColorer

– Martin Ender – 2015-11-08T21:18:51.117

10

Vim, 44 bytes

33o<CR>Fizz<CR><Esc>qqABuzz<Esc>5kq19@q:%s/^$/\=line('.')<CR>

On vimgolf.com we have the classic Remember FizzBuzz?, which is similar to this, but keeps the numbers on all the lines. There's also Neither Fizz nor Buzz, which uses a similar format, but provides a useful input file. Those small differences drastically change the optimal solution. I did exactly this same variation 2 years ago in the edit to this reddit post. I had to check whether visual increment (not available back then) creates an improvement, like it has for the other variations, but it looks like it hasn't.

  • 33o<CR>Fizz<CR><Esc>: Create the Fizz lines AND the blank lines with a simple insert mode repeat. Much quicker than a macro. AFAIK first discovered by @KersonHsiao in the vimgolf.com version, and used by every top solution since.
  • qqABuzz<Esc>5kq19@q: A very simple macro appends the Buzzes.
  • :%s/^$/\=line('.')<CR>: Replaces all blank lines with that line's line number. The expression replacement is very long, so this tactic is rarely used in vimgolf, but the alternatives are all worse.

udioica

Posted 2015-09-24T19:23:54.480

Reputation: 2 381

9

TrumpScript, 938 bytes

As always nothing is, 1000001 minus 1000000;
And Putin is, 1000003 minus 1000000; great
Just as Trump is, 1000005 minus 1000000; even better
Also as America is, Putin times Trump; the best
Most importantly Ivanka is, 1000101 minus 1000000;
And believe me that Hillary is nothing
As long as, Hillary thinks less of Ivanka;:
China is friends with Hillary
Democrats are idiots like Hillary
Obama is in line with Hillary
As long as, China thinks its more than America;:
Make China, China minus America;!
As long as, Democrats fear more Trump;:
Make Democrats, Democrats minus Trump;!
As long as, Obama gets more arsenal against Putin;:
Make Obama, Obama minus Putin;!
If everybody thinks, America is China?;:
Say "FizzBuzz"!
Otherwise: if we ask, Democrats are Trump?;:
Say "Buzz"!
Otherwise: what if, Obama is Putin?;:
Say "Fizz"!
Otherwise do this: tell Hillary all her lies!!!
Hillary is, as always Hillary plus nothing;!
America is great.

Try it online!

I was quite bored... Not too efficient, but fun!

Pseudocode:

var nothing = 1, Putin = 3, Trump = 5, America = Putin * Trump, Ivanka = 101, Hillary = nothing;
while Hillary < Ivanka
    var China = Democrats = Obama = Hillary;
    while China > America
        China = China - America;
    while Democrats > Trump
        Democrats = Democrats - Trump;
    while Obama > Putin
        Obama = Obama - Putin;
    if China == America
        print "FizzBuzz";
    else if Democrats == Trump
        print "Buzz";
    else if Obama == Putin
        print "Fizz";
    else
        print Hillary;
    Hillary = Hillary + nothing;
America is great.

Grzegorz Puławski

Posted 2015-09-24T19:23:54.480

Reputation: 781

9

Python 2, 61 60 bytes

for i in range(1,101):print"Fizz"*(i%3<1)+"Buzz"*(i%5<1)or i

Blue

Posted 2015-09-24T19:23:54.480

Reputation: 26 661

This is invalid: it prints 0 at the start – Beta Decay – 2015-09-24T19:38:36.937

1You could use either i+1 or range(1,101) to fix it. – ASCIIThenANSI – 2015-09-24T19:40:03.450

Now it only goes up to 99. – Zach Gates – 2015-09-24T19:48:07.300

I already have 56 FYI. – feersum – 2015-09-24T19:48:41.500

2the output is also straight up incorrect. 89 prints out a FizzBuzz whereas 90 is printed as 90 – Kevin W. – 2015-09-24T19:50:45.463

3Have you actually tested this program? – Beta Decay – 2015-09-24T19:57:02.053

To whoever downvoted, the program works as it is now. – Blue – 2015-09-24T21:16:02.127

9

JavaScript, 65 bytes

for(i=0;i++<100;console.log((i%3?'':'Fizz')+(i%5?'':'Buzz')||i));

The shortest approach I've found yet. Perhaps there's a better one; suggestions are welcome. This was originally flagged ES6, but this works in ES5, and to my knowledge there's not a shorter way with ES6 features.

Here's another attempt, using .slice and some complicated maths for a total of 66 bytes:

for(i=0;i++<100;console.log('FizzBuzz'.slice(i%3&&4,i%5?4:8)||i));

(Thanks to Ben Fortune for a couple of handy tricks!)

ETHproductions

Posted 2015-09-24T19:23:54.480

Reputation: 47 880

2You could shorten your second attempt to for(i=0;i++<100;console.log('FizzBuzz'.slice(i%3&&4,i%5?4:8)||i)); – Ben Fortune – 2015-09-25T10:13:20.757

If you move console.log(...) outside for(...;...;...), you can drop the semicolon. – Dennis – 2015-10-03T15:54:44.217

This is old, but ES6 plus Dennis= 61 bytes:

     for(i=0;i++<100;)console.log(i%3?i:'fizz'+`${i%5?'':'Buzz'}`) I can't make it a code block because the template string won't show up correctly
 – Generic User  – 2015-11-15T18:23:08.503

@GenericUser That doesn't quite work; it never prints Buzz by itself. To insert code with backticks in it, just use 2 or 3 backticks on each end. – ETHproductions – 2015-11-15T18:31:34.407

8

Julia, 64 bytes

for i=1:100 x="Fizz"^(i%3<1)*"Buzz"^(i%5<1);println(x>""?x:i)end

Alex A.

Posted 2015-09-24T19:23:54.480

Reputation: 23 761

7

Brainfuck, 425 bytes

-[>+>+<<-----]>--->-->++++++++++>->++++++++++>+++++++++>>>+++>>>+++++>>>>>-[<+<+>>-------]<---<--->---->>-[<++>-----]<+++>>>----[<+++<+++>>--]<-----<<<<<<<<<<<<<<[<++++++++++[>>[->>-<]>+[->>>>>-[<<<-[<<<<<<<<.>>>>>>>>>>-<]>+[->]<<+>>>>>-<]>+[->]<<+<<<<]>-[>>>-[<<<<<<<<<<.>>>>>>>>>>>>-<]>+[->]<<+<-<]>+[>>>>>.>>.>..<<<<<<<<<+++>->]>-[>>-<]>+[>>>.>>>.<..<<<<<<+++++>->]<<<<<<<<<<<<+>.>-]<<----------<+>>>>-]>>>>>>>>>>>.>>>.<..

Try it online!

Explanation

Cell indexes in comments are in hexadecimal to match numbering in bfdev debug view.

# #####################
# ##### VARIABLES #####
# #####################

# C1 & C2: 48 (ascii 0)
-[>+>+<<-----]>--->-->
# C3: 10 (ascii LF)
++++++++++>
# C4: Singles counter
->
# C5: Tens counter
++++++++++>
# C6: is1to9 if countdown
+++++++++>
# C7: 0 to enter/exit is1to9, or 1 to enter is10to99
>
# C8: 0 to not enter is10to99
>
# C9: isMultiOf3 if countdown
+++>
# CA: 0 to exit isMultiOf3, or 1 to enter !isMultiOf3
>
# CB: 0 to not enter !isMultiOf3
>
# CC: isMultiOf5 if countdown
+++++>
# CD: 0 to exit isMultiOf5, or 1 to enter !isMultiOf5
>
# CE: 0 to not enter !isMultiOf5
>
# CF: 70 F, and put C13 to 70
>>-[<+<+>>-------]<---<--->
# C10: 66 - ascii B
---->
# C11: 105 - ascii i
>-[<++>-----]<+++>
# C12: 122 - ascii z, and put C16 to 122
>>----[<+++<+++>>--]<
# C13: 117 - ascii u
-----
# Goto C5
<<<<<<<<<<<<<<

# #################
# ##### LOGIC #####
# #################

# While C5 (tens counter): Print 1-99
[
# Restore C4: singles counter
  <++++++++++
# For 0 to 9, using singles counter
  [
#   Goto C6
    >>
#   If is1to9
    [
#     Decrement is1to9 countdown
      -
#     Prepare else condition at C8
      >>-<
    ]
#   Goto C7 or C8
    >+
#   Else If C7: is10to99
    [
#     Decrement C7
      -
#     Goto CC
      >>>>>-
#     If is not multi of 5
      [
#       Goto C9
        <<<-
#       If is not multi of 3
        [
#         Print C1: tens
          <<<<<<<<.
#         Prepare else condition at CB
          >>>>>>>>>>-
#         Goto CA
          <
        ]
#       Goto CA or CB
        >+
#       Else If is multi of 3
        [
#         Goto CA, restore, goto CB
          ->
        ]
#       Goto C9 and restore
        <<+
#       Prepare else condition at C1E
        >>>>>-
#       Goto C1D
        <
      ]
#     Goto CD or CE
      >+
#     Else If is multi of 5
      [
#       Goto CD, restore, goto CE
        ->
      ]
#     Goto CC and restore
      <<+
#     Goto C8
      <<<<
    ]
#   Goto C9
    >-
#   If is not multi of 3
    [
#     Goto CC
      >>>-
#     If is not multi of 5
      [
#       Print C2: singles
        <<<<<<<<<<.
#       Prepare else condition at CE
        >>>>>>>>>>>>-
#       Goto CD
        <
      ]
#     Goto CD or CE
      >+
#     Else If is multi of 5
      [    
#       Goto CD, restore, goto CE
        ->
      ]
#     Goto CC and restore
      <<+
#     Prepare else condition at CB
      <-
#     Goto CA
      <
    ]
#   Goto CA or CB
    >+
#   Else If is multi of 3
    [
#     Print Fizz
      >>>>>.>>.>..
#     Goto C9 (If is not multi of 3)
      <<<<<<<<<
#     Restore C9
      +++
#     Goto CA, decrease, goto CB
      >->
    ]
#   Goto CC
    >-
#   If is not multi of 5
    [
#     Prepare else condition at CE
      >>-
#     Goto CD
      <
    ]
#   Goto CD or CE
    >+
#   Else If is multi of 5
    [    
#     Goto C10 and print Buzz
      >>>.>>>.<..
#     Goto CC (If is not multi of 5) and restore
      <<<<<<+++++
#     Goto CD, decrease, goto CE
      >->
    ]
#   Goto C2: singles, and increment
    <<<<<<<<<<<<+
#   Print C3: LF
    >.
#   Decrement C4: singles counter
    >-
  ]
# Restore C2: singles ascii 
  <<----------
# Increment C1: tens ascii
  <+
# Goto C5 (tens counter) and decrement it 
  >>>>-
]   
# Goto C10 and print Buzz
>>>>>>>>>>>.>>>.<..

Forcent Vintier

Posted 2015-09-24T19:23:54.480

Reputation: 103

1

Thought I'd let you know I beat your score ;)

– Jo King – 2017-11-24T09:43:00.283

7

BuzzFizz, 86 bytes

$a++
if3\$a:print"Fizz"
if5\$a:print"Buzz"
else:print$a
print"\n"
if100\$a:#
else:loop

Try it online!

Explanation

Despite being golfed, all you have to do is to add a bit of horizontal whitespace and a few comments to get possibly one of the clearest and most readable FizzBuzzes ever. (Vertical whitespace is significant in BuzzFizz, apart from (by popular demand) the trailing newline, so it's necessary even in a golfed program.)

# Counters start at 0. So $a will be increased to 1 on the first iteration.
# On subsequent iterations, it counts up by 1 each time.
$a++

# BuzzFizz supports only one operator: \, the "divides into" relational
# operator. So you'll be seeing that every time there's an if statement.
# It's pretty helpful for a fizzbuzz!
if 3\$a: print "Fizz"
if 5\$a: print "Buzz"

# The "else" statement attaches to *both* "if" statements simultaneously;
# it'll only run if neither of them did. "else" always attaches to all
# "if" statements since the preceding "else", so sometimes a dummy "else"
# statement is needed in order to clear the state. We don't need to
# resort to that for our FizzBuzz program, though.
else: print $a

# Now we've printed Fizz/Buzz/FizzBuzz/the number, print a newline.
print "\n"

# Our loop ends when $a becomes 100. 100 is the lowest positive integer
# that's divisible by 100, so we can use a divisibility test to find
# the end of the loop. We negate the test via the use of a comment as
# the body of the "if" statement (an "if" body cannot be empty in
# BuzzFizz, but a comment counts as a statement).
if 100\$a: # do nothing

# If $a is *not* divisible by 100, we have another iteration. So loop
# back to the start of the program.
else: loop

Discussion

In addition to the commands seen in the FizzBuzz program above, BuzzFizz also supports input (if you use an identifier like a with no leading $, the program will ask for its value; you can use a statement like clear a to reset the value so that the program asks for it again the next time it's used). Other than that, the above program shows off all the features of the language; in other words, we have a complete language built entirely out of the operations you need to write a simple FizzBuzz program (thus the name).

Despite its inspiration, BuzzFizz is not specialised merely for FizzBuzzes; you can take the FizzBuzz program apart, put it together in other ways, and solve a surprisingly large range of problems. For example, the Esolang page for the language has a primality tester and a program which adds two positive numbers. (The primality tester is simpler than the addition program; given BuzzFizz's choice of operator, this probably shouldn't be too surprising.)

That said, the language is (intentionally) not Turing-complete; the original inspiration of the language was to act as a counterexample to people who made claims of the form "any language that can do X must be Turing-complete", as the most common choices of X don't actually require it. On the other hand, it's also (intentionally) very powerful for a sub-Turing language; it's fairly hard to come up with simple problems that BuzzFizz can't solve and Turing-complete languages can.

ais523

Posted 2015-09-24T19:23:54.480

Reputation: 11

7

80386 machine code + DOS, 75 68 bytes

NOTE: This is a reply to @anatolyg's really clever 2015 answer, with a few tweaks to reduce the score by 7 bytes. I'm only submitting this as a separate answer because it wouldn't be possible to explain fully in a comment.

Changes:

  • Use SI to reset BX since DOS sets SI initially to 100H (ref) instead of an imm. (-1 byte)
  • Instead of using a 3/5 counter in DH/DL, use AAM for modulo operations on counter. AAM is a 2 byte instruction that's effectively a byte-length DIV that can accept an imm value as the divisor and also sets ZF if AL mod n = 0. @Peter Cordes touches on this in his very brilliant post about FizzBuzz in assembly. (-5 bytes)
  • Instead of CR/LF, use LF/CR (the order doesn't matter to DOS). This translates to an instruction that does not modify the startup value of AX (in fact it zeroes out AL) so we can eliminate the xor ax,ax and save two bytes. It does come at a cost because 0A 0D is only a two-byte instruction so the rest of the 24xx instruction needs to be padded with one more byte. (-1 byte)

Unassembled:

0A 0D           or cl, [di]             ; LF and CR bytes (newline)
24 00           and al, 0               ; DOS string delim ('$') + pad byte
B1 64           mov cl, 100             ; set loop counter to 100 

            main_loop: 
8B DE           mov bx, si              ; init bx to 100h 
40              inc ax                  ; increment fizzbuzz counter 
50              push ax                 ; save fizzbuzz counter

50              push ax                 ; save ax from getting clobbered by AAM 
D4 05           aam 5                   ; AL = AL mod 5, ZF if AL = 0
58              pop ax                  ; restore ax 
75 0A           jnz short buzz_done     ; jump if not a 'Fizz'
83 EB 04        sub bx, 4               ; offset for output string 
66C707 7A7A7542 mov dword ptr [bx], 'zzuB' 
            buzz_done: 

50              push ax 
D4 03           aam 3                   ; AL = AL mod 3, ZF if AL = 0
58              pop ax 
75 0A           jnz short fizz_done     ; jump if not a 'Buzz'
83 EB 04        sub bx, 4 
66C707 7A7A6946 mov dword ptr [bx], 'zziF' 

            fizz_done: 

84 FF           test bh, bh             ; either a Fizz or a Buzz? (BX not changed)
74 0C           jz short num_done       ; if so, do not display a digit

            decimal_loop: 
D4 0A           aam;                    ; AL = AL mod 10
04 30           add al, '0'             ; convert to ASCII
4B              dec bx 
88 07           mov [bx], al 
C1 E8 08        shr ax, 8               ; 'mov al, ah', ZF if AL = 0
75 F4           jnz decimal_loop 

            num_done: 
8B D3           mov dx, bx              ; set dx to output string pointer
B4 09           mov ah, 9 
CD 21           int 21h 
58              pop ax                  ; restore fizzbuzz counter

E2 C3           loop main_loop 
C3              ret 

xxd binary:

00000000: 0a0d 2400 b164 8bde 4050 50d4 0558 750a  ..$..d..@PP..Xu.
00000010: 83eb 0466 c707 4275 7a7a 50d4 0358 750a  ...f..BuzzP..Xu.
00000020: 83eb 0466 c707 4669 7a7a 84ff 740c d40a  ...f..Fizz..t...
00000030: 0430 4b88 07c1 e808 75f4 8bd3 b409 cd21  .0K.....u......!
00000040: 58e2 c3c3                                X...

640KB

Posted 2015-09-24T19:23:54.480

Reputation: 7 149

4Of course it's a competing answer! It has nice ideas. Competition of this kind is exactly what this site needs! – anatolyg – 2019-08-27T22:47:44.120

7

Common Lisp, 123 116

(dotimes(i 100)(loop for(m s)in'((3"Fizz")(5"Buzz"))if(=(mod(1+ i)m)0)do(princ s))(do()((fresh-line))(princ(1+ i))))

Pretty-printed

(dotimes (i 100)
  (loop for (m s) in '((3 "Fizz") (5 "Buzz"))
        if (= (mod (1+ i) m) 0)
        do (princ s))
  (do () ((fresh-line)) (princ (1+ i))))

The do/fresh-line trick

The inner loop iterates over ((3 "Fizz") (5 "Buzz")) for each i and, according to the result of the two consecutive mod operations, eventually prints:

  • nothing
  • or Fizz
  • or Buzz
  • or FizzBuzz

fresh-line is a nice little function that as far as I know is only found in Common Lisp. It adds a newline only if necessary, and returns T only when the newline was added. For the above situations, according to whether we printed something or not, the return values of (fresh-line) are thus respectively:

  • NIL
  • T
  • T
  • T

So I know that the integer must be printed only when we did not print a fresh-line. But if I print the integer, I must also print a newline after it. That's why there is a DO.

DO is a basic yet almighty looping construct that iterates until a condition is met. Here, the condition is the return value of (fresh-line). It it tested before each iteration of the body of the loop, notably the first one. So if the test returns T, then we exit the DO. Otherwise, we execute the body, which prints the integer. Then, we execute the test once again and this time, it returns T because current line is "dirty" (there is an integer printed now).

coredump

Posted 2015-09-24T19:23:54.480

Reputation: 6 292

Clever! I don't think I can change my CL answer to beat it. – nanny – 2015-09-25T16:42:00.593

@nanny If that can comfort you, I don't think I can either. I saw your answer, it was hard to beat. – coredump – 2015-09-25T16:47:33.490

Great answer. I learnt some from it and don't understand it fully yet. However I think I've managed to beat you by 13 bytes using different method.

– None – 2017-02-17T22:45:18.150

7

Mathematica, 83 75 73 67 62 bytes

Print/@(#/.(##&[15#->FizzBuzz,3#->Fizz,5#->Buzz]&)/@#&@Range@100)

I do not think that this could be golfed any further. Thanks to branislav for helping me golf this.

LegionMammal978

Posted 2015-09-24T19:23:54.480

Reputation: 15 731

golf it down to 66 bytes by first removing all quotation marks, second using ...\\Column instead of Print/@(...) – branislav – 2015-10-30T16:39:22.607

then how about Print/@% – branislav – 2015-11-02T05:30:50.697

@branislav It doesn't end up saving any bytes. – LegionMammal978 – 2015-11-02T11:24:13.987

62 bytes: Print/@(#/.(##&[15#->FizzBuzz,3#->Fizz,5#->Buzz]&)/@#&@Range@100), a one-liner without exotic characters, you asked for it ;D I think now we're at the end – branislav – 2015-11-02T12:52:39.827

6You mean Mathematica doesn't have a FizzBuzz builtin? – Mego – 2015-11-15T05:02:04.823

You can save 1 byte with Echo – shrx – 2016-03-07T10:22:28.357

@shrx Echo adds a leading >> to the output. – LegionMammal978 – 2016-03-07T12:28:34.527

This is a fantastic answer, but unfortunately I don't think it is valid in Mathematica 11 as it yields {Null, Null, Null.....Null} after the output. Is it saveable? Otherwise, I have Row@Pick[{Fizz,Buzz},#~Mod~{3,5},0]/.{}->{#}&~Array~100//Column which comes in at two bytes longer. – A Simmons – 2017-01-20T17:08:14.683

1I should make it clear that I don't think that not working in the up-to-date version in any way invalidates this answer! But I'm interested to know what the best solution is in 11. – A Simmons – 2017-01-20T17:10:13.333

Heavily inspired by a discussion on Mathematica SE, this comes in at 61 fizzbuzz[#,,fizz,,buzz][[#~GCD~15~Mod~15]]&~Array~100//Column – A Simmons – 2017-01-20T17:35:50.290

@ASimmons The list of Nulls doesn't get output to STDOUT, and neither does the actual output on your proposed solution. – LegionMammal978 – 2017-01-20T22:07:38.743

7

C++, 130 126 119 115

#include<iostream>
int i;int main(){for(auto&o=std::cout;++i<101;o<<'\n')i%3?o:o<<"Fizz",i%5?i%3?o<<i:o:o<<"Buzz";}

Live version.

mattnewport

Posted 2015-09-24T19:23:54.480

Reputation: 1 579

7

MoonScript, 83 82 bytes

[print(i%15==0and"FizzBuzz"or(i%3==0and"Fizz")or(i%5==0and"Buzz")or i) for i=1,100]

Digital Veer

Posted 2015-09-24T19:23:54.480

Reputation: 241

5Welcome to Programming Puzzles & Code Golf! – Dennis – 2015-09-26T05:27:54.717

7

Snowman 1.0.2, 97 chars

)1vn101nR:du*_/3NmO0eQ)(#5NmO0eQ}~(~%@or(%nO?_/)#%@{%@tS?)aRsP@@"Fizz"_aRsP\"Buzz"aRsP?)10wRsP;aE

How does it work, you ask? ... I have no idea. I might edit in a full explanation at some point if I ever decide to try to understand this again.

(Pulled directly from Snowman's examples directory.)

Doorknob

Posted 2015-09-24T19:23:54.480

Reputation: 68 138

6

Common Lisp, 103 101 96 93 84 bytes

(dotimes(i 101)(format t"~v^~[Fizz~[Buzz~]~:;~[Buzz~:;~a~]~]
"i(mod i 3)(mod i 5)i))

Try it online!

It's shorter than other CL solution and it uses different method. Conditions are handled inside format function.

-5 bytes - shorter version of handling i=0

-3 bytes - ~^ with only one parameter seems to work as if second parameter was 0, which is saves 2 bytes. Last byte is saved by substituting ~% by <enter>

-9 bytes - by ASCII-only

user65167

Posted 2015-09-24T19:23:54.480

Reputation:

You can use ~[ instead of ~:[ and remove the (= ... 0) to reduce it to 84 bytes (with a bit of rearrangement). (not posting link because it would spoiler current code-golf.io best) – ASCII-only – 2018-05-16T09:26:43.273

@ASCII-only Thank you for suggestion but it seems unobvious, how to do it. Without (=(mod i 5)0) I seem to need to handle residues of 1,2,3,4 separately (and similiarily for (=(mod i 3)0): 1 and 2). – None – 2018-05-24T20:08:22.180

1No... just use ~:; to add a default fallback: (dotimes(i 101)(format t"~v^~[Fizz~[Buzz~]~:;~[Buzz~:;~a~]~]<newline>"i(mod i 3)(mod i 5)i)) where <newline> is replaced with literal newline – ASCII-only – 2018-05-24T23:33:21.713

@ASCII-only Thank you, I edited the answer. – None – 2018-05-25T16:28:37.680

6

Groovy, 69 Bytes

(1..100).each{i->println i%15?(i%5?(i%3?i:'Fizz'):'Buzz'):'FizzBuzz'}

The Coder

Posted 2015-09-24T19:23:54.480

Reputation: 279

2Can save 2 bytes using 1.upto(100){} and no parenthesis are needed in your answer, resulting in: 1.upto(100){i->println i%15?i%5?i%3?i:'Fizz':'Buzz':'FizzBuzz'}​ +1 though :). – Magic Octopus Urn – 2016-10-13T17:49:14.960

6

Japt, 45 44 43 39 36 35 33 32 31 bytes

Japt is a shortened version of JavaScript.

Lò1@"Fizz"pXv3)+"Buzz"pXv5)ªX÷

Try it online!

How it works

Lò1@"Fizz"pXv3)+"Buzz"pXv5)ª XÃ ·
Lò1@"Fizz"pXv3)+"Buzz"pXv5)||X} qR

Lò1       // Create the inclusive array [1...100].
@         // Map each item X in this range to:
 "Fizz"p  //  "Fizz" repeated:
  Xv3)    //   if X is divisible by 3, 1 time, otherwise, 0 times;
 +        //  concatenated with
 "Buzz"p  //  "Buzz" repeated:
  Xv5)    //   if X is divisible by 5, 1 time, otherwise, 0 times.
 ||X      //  If the result is an empty string, set it to X.
} qR      // Join the range with newlines.
          // Implicit: output last expression

Old version, 32 bytes:

Lo@"FizzBuzz"s°X%3©4X%5?4:8 ªX÷
Lo@"FizzBuzz"s++X%3&&4X%5?4:8 ||X} qR

Lo            // Create the range [0..100).
@             // Map each item X in this array to:
 "FizzBuzz"s  //  "FizzBuzz".slice(
  ++X%3&&4    //   if ++X is divisible by 3, 0; else, 4,
  X%5?4:8     //   if X is divisible by 5, 8; else, 4).
 ||X          //  If the result is an empty string, set it to X.
} qR          // Join the range with newlines.
              // Implicit: output last expression

Alternate version (45 44 40 38 bytes): (Note: this doesn't work in the current version of Japt)

1o#e £(X%3?":Fizz" +(X%5?":Buzz" ªX} ·
1o#e m@(X%3?":Fizz" +(X%5?":Buzz" ||X} qR

1o#e          // Create an array of 1 to 100.
m@            // Map each item X in this array to:
 (X%3?":Fizz" //  If X is divisible by 3, "Fizz"; else, an empty string
 +            //  concatenated to:
 (X%5?":Buzz" //  if X is divisible by 5, "Buzz"; else, an empty string.
 ||X          //  If the result is an empty string, set it to X.
} qR          // Join the range with newlines.
              // Implicit: output last expression

Suggestions welcome!

ETHproductions

Posted 2015-09-24T19:23:54.480

Reputation: 47 880

6

Rotor, 32 31 bytes

1N2{3%!"Fizz"~5%!"Buzz"N$?~N}\

This has one unprintable, so here's a hexdump:

0000000: 314e 7f32 7b33 2521 2246 697a 7a22 7e35  1N.2{3%!"Fizz"~5
0000010: 2521 2242 757a 7a22 4e24 3f7e 4e7d 5c    %!"Buzz"N$?~N}\

Explanation:

1  Push a one to the stack.
N  Push a newline.
^? Spooky invisible unprintable that pushes 100 to the stack.
2  Pushes a two to the stack. 
{  Starts block.
  3%      Takes mod 3 of the top number on the stack.
  !"Fizz" If falsy, push "Fizz".
  ~       Push the contents of the register.
  5%      Takes mod 5.
  !"Buzz" If falsy, push "Buzz".
  N$      Compares the top value of the stack to a newline. (this doesn't pop the values off the stack)
  ?~      If truthy, push the contents of the register.
  N       Push a newline.
}\ For loop between 2 and 100, pushing the counter to the register and stack each time.

Try it online. (note that it is very slow)

Check out Rotor.

a spaghetto

Posted 2015-09-24T19:23:54.480

Reputation: 10 647

6

Brainfuck, 16321 3602 1597

Almost as short as Java. This is just the trivial answer generated by another program, This is still a computer generated answer, but I am sure there are way shorter solutions! The general idea is initializing the cells to 4 B F i u z. If the program has to output a number, it just goes to the first cell and manipualtes it, if it is one of the letters, it will just jump to the corresponding cell and output it.

++++++++++<<+++++++[>+++++++<-]>[>>+>+>+>++>++>++<<<<<<<-]>>+++>+++++++++++++++++>+++++++++++++++++++++>+++++++>+++++++++++++++++++>++++++++++++++++++++++++<<<<<---.<.>+.<.>>>.>.>>..<<<<<<.>++.<.>>.>>>.>..<<<<<<.>>>.>.>>..<<<<<<.>+++.<.>+.<.>>>.>.>>..<<<<<<.>>.>>>.>..<<<<<<.>-------..<.>>>.>.>>..<<<<<<.>.++.<.>--.+++.<.>>>.>.>>..<<<<.>>>.>..<<<<<<.>---.+++++.<.>-----.++++++.<.>>>.>.>>..<<<<<<.>------.++++++++.<.>>.>>>.>..<<<<<<.>>>.>.>>..<<<<<<.>-------..<.>.+.<.>>>.>.>>..<<<<<<.>>.>>>.>..<<<<<<.>-.++++.<.>>>.>.>>..<<<<<<.>----.++++++.<.>------.+++++++.<.>>>.>.>>..<<<<.>>>.>..<<<<<<.>------.--.<.>++.-.<.>>>.>.>>..<<<<<<.>+.+.<.>>.>>>.>..<<<<<<.>>>.>.>>..<<<<<<.>-.++++.<.>----.+++++.<.>>>.>.>>..<<<<<<.>>.>>>.>..<<<<<<.>----.---.<.>>>.>.>>..<<<<<<.>+++.-.<.>+..<.>>>.>.>>..<<<<.>>>.>..<<<<<<.>.++.<.>--.+++.<.>>>.>.>>..<<<<<<.>---.+++++.<.>>.>>>.>..<<<<<<.>>>.>.>>..<<<<<<.>----.---.<.>+++.--.<.>>>.>.>>..<<<<<<.>>.>>>.>..<<<<<<.>++.+.<.>>>.>.>>..<<<<<<.>-.+++.<.>---.++++.<.>>>.>.>>..<<<<.>>>.>..<<<<<<.>---.-----.<.>+++++.----.<.>>>.>.>>..<<<<<<.>++++.--.<.>>.>>>.>..<<<<<<.>>>.>.>>..<<<<<<.>++.+.<.>-.++.<.>>>.>.>>..<<<<<<.>>.>>>.>..<<<<<<.>-.------.<.>>>.>.>>..<<<<<<.>++++++.----.<.>++++.---.<.>>>.>.>>..<<<<.>>>.>..<<<<<<.>+++.-.<.>+..<.>>>.>.>>..<<<<<<.>.++.<.>>.>>>.>..<<<<<<.>>>.>.>>..<<<<<<.>-.------.<.>++++++.-----.<.>>>.>.>>..<<<<<<.>>.>>>.>..<<<<<<.>+++++.--.<.>>>.>.>>..<<<<<<.>++..<.>.+.<.>>>.>.>>..<<<<.>>>.>..<<<<<<.>.--------.<.>++++++++.-------.<.>>>.>.>>..<<<<<<.>+++++++.-----.<.>>.>>>.>..<<<<<<.>>>.>.>>..<<<<<<.>+++++.--.<.>++.-.<.>>>.>.>>..<<<<<<.>>.>>>.>..<<<<<<.

flawr

Posted 2015-09-24T19:23:54.480

Reputation: 40 560

Nice solution! I could get to 425 bytes by manually writing the brainfuck code.

– Forcent Vintier – 2016-12-27T13:04:49.167

5

J, 45 bytes

New Version, thanks to Bolce Bussiere:

(,&((;,>)Fizz`Buzz)@":{~+.&3-~0:<5&|)"0>:i.100

Old version (52 bytes):

(,&('Fizz'(,>@;;)'Buzz')@":{~+.&3-~0:~:5&|)"0>:i.100

Explanation

Best explained by breaking it up into smaller verbs. Overall the main working portion is a train:

getlist {~ getindex

where getlist i returns a 4-length list of the default format of i, 'FizzBuzz', 'Fizz', and 'Buzz'; and getindex i returns -1 if i is divisible by 5 only, -2 if divisible by 3 only, 1 if divisible by both, and 0 otherwise. The verb {~ grabs the right argumentth element from its left argument, the list created by getlist, where the index is modulo'd by the length of the list, meaning -1 will grab the last element, -2 the second-to-last, etc.

In

getlist=:,&('Fizz'(,>@;;)'Buzz')@":

": gets the default format of i, and then ,&('Fizz'(,>@;;)'Buzz') appends it to the beginning of the list created using the train ,>@;; on the two arguments 'Fizz' and 'Buzz' (append them and raze them, then raze those results together and unbox each item), in the new version ((;,>)Fizz`Buzz) does essentially the same thing but takes advantage of the ` that boxes, then appends the two strings before applying the train ;,> on the resulting list of boxes (unbox each element; raze the elements together to get FizzBuzz; append the unboxed elements with FizzBuzz)

In

getindex=:+.&3-~0:~:5&|

+.&3 gets the GCD of i and 3, and 5&| returns i modulo 5. The train 0:~:5&| returns 1 if 5&| is unequal (~:, or in the new version < because the result of 5&| will always be greater than or equal to 0) to the result of the constant function 0: (which returns 0 for any argument) and 0 otherwise, then getindex is a train that, from this value, subtracts +.&3 resulting in the return values given above.

The boring parts are the "0 which simply tells the verb to operate on atoms of any argument given to it, and >:i.100, which returns a list of integers from 1 to 100 (inclusive).

Bailis Cremey

Posted 2015-09-24T19:23:54.480

Reputation: 51

Using < instead of ~: saves a byte – Bolce Bussiere – 2019-04-06T16:42:26.877

1And (;,>)Fizz\Buzzinstead of'Fizz'(,>@;;)'Buzz'` saves another 5 – Bolce Bussiere – 2019-04-06T16:56:47.183

1@BolceBussiere < instead of :~:? – ASCII-only – 2019-04-08T04:17:56.677

@ASCII-only the first : belongs to the verb 0: that returns the constant 0. The verb ~: represents 'not equal' – Bailis Cremey – 2019-04-09T17:29:37.367

Idk, using just constant 0 worked for me – ASCII-only – 2019-04-09T23:02:02.827

5

Seed, 6015 bytes

186 83944644497775792185807323999861330742900673481712359255839929374667216476568023851764637813248013688693896717275687232066153870107749175160194707761486575005885313952906442913325967953944535811512056079183251514390746052490451307246213606447865255212286265116943188690839445165359981774554198082946825007384980162551436390435260155582466874315352220541140434954811560506556477075852586817070090764184077321583489797358147025926992986354865415277367374043398355163643621296927936732212800075642321038031920620549375319366961667358107695950468557182519902148699776620624078332688843597417318685229781090303723160175745852091928346724348001020777912570918121340035523698691520422590527296248455779012094897281946771732844646467975422651655880202725095981882371807518829844157636552230152953535332201239998966830698645115246907049972204010095894629001206397276344975636564553238199728981112245810583644580269593382612869323054013019350314231784293448249910440692956496060253971880373279161390518237118507378691330341470412624728172421405109963475552981299919837091765136501358887135317778357279769289706821629750840213676581513947891276551415821187603189444230553630205086966993211879390093045277089486589385876312541940492767981701353769007246001400130719416118275492304807198011860072050303044225722194337717896831470037434122578382321765362062455130027125953869723625862069785410531287781468150359623495258126317807476517184801674197008747267394632928708383370640309530427431150403028006421518064783676469959724647961395869176187323826585310379142853088186864023708457159764123364029018721951815248751431170413579315400528983481702298849209797951129827235189965388114007169146563257209800975334610910397591190300324319540160364733177122449656422045835924029442449258975425381755648345550014417207471617919736685787448764321614059138375253980386335770138273578332418379763049794151811098188219754733324389355566317376598492318359989945589480418455750455469859956801589082779968271578522034926104268403877968397758570110853038536860556853388613997493905742068279137736678857073233174739380697685907170886092925173057794582407478105690770633669349947638020604803238951194381273510993928897230197983256465537488284258216944902276278712201715008765995404107536372438956009631805114079400698265046614085687812688769068889878215788959245601084883372435344000194364054441952170474833494604130017222942459218768152451353838900515646024764453476453552863938005162079649698291854043301771100462916706520075039044805956181705047266329114921035274711980897862579454154525144505597823262540025190878917613039796282312555295659294071407630514652646787462515667390800389392114746442068094785615537685660298361617697365653764669207754605147347324074541222276275532258194690926246437097055706104108319469003781845674958634242078791475826910418111428349167152839025683587469305219626924263962611094845308744968793376752461012553325189830937237777556407663277494722334379175044299145527685100424059993166500276116324651034389342857099326382267792125696063602436504279969923412378117936327869017861642388185619118723658181098871790872093500520584752433465443515989483851486224923341213990357424279098636563794743080022540640677640107176034203326304825856510242291526956869439836743210321616337131260522898066320086593786007891762080406650341513081903510025534886914361255147039463158189995500627220823997958074917925862170348467342212390436963261050291735696261617106196786273505443408966191019872244618002281427523777003325474230066462489531195157755555344637353155356279454281010364750875012491070816465270498678197434494849001514802132418781410405222031814823702582955264273367316636558580379660009282902598817700470535664545017234816209988594892835104965686956867851308392004044845547855039571721575449154495443479356960829759209226823917197487855397504141411230632224369201022681688301238065753737278463677847356448662974398206270856674118500884955014781944009536761710654880983265123955150729759406311220705702903728217724237231225228243114081826682040349685205121446193821261139703572900811243143912445467975694459999888915923116875430564637390061881889161512304819029656014338113772447267072899546161543780769850725712979853265124144813517511575434597175140160445249538753447856073028845070404104820699013418827593400549228758486817648053770622330987136941236768786640613654490823959024174575959620155957372041756651311988259843620347948677131103848960623371212015137053539005334518693964703094514744873758157905983139622925587291886231049371800498250086745691716656644176053612172113439907334397406577774498757112425437339205922869531575921611548158798375762386782843394828401126984185115349224303420458491251207091698634206841378497320259972637725826224808114267917428717816623368840721796784587349258491132128347823644310226457190477267965710821892576687103122134712656694901146343938508484308662925632874468476850854977933467327214644382364732022885458172449643330918925157997124690072012401561398600599725096512808715148150880033416494352767432615596760722206416684175988533830899565642405659319720681197534141300323187308210290375660950200938389996580887564670049743784962037885099514826194024014058093062057706139814777110125812527054724707373942053107785831307633110641398607263726549612409340127167852023607787965086360296071952107945138419803900924977980375619565210182772121849111987355981226968062629667279278470647719759267716675652568099185449478479471691254158308189631416224208590609150412906273490206303890853713104183863050119383440553687111132467944761189779633340481533657859382354192428154204487886313458547651002779223927726608436086877353829832057341247094095114657693381028772025327489391112902949559367893876211447144802835381133403893955836438518252858893637260806405255643702579004661210305919494653119109150790218729956868835489222681506976514342204634574313468575534020458319909578144280137077342941741913678288702984697189445809519253013406175446129538246339672293879388869701830984873958965248

Try it online!

Krzysztof Szewczyk

Posted 2015-09-24T19:23:54.480

Reputation: 3 819

Oh, my generator must have glitched. I'll look on this – Krzysztof Szewczyk – 2019-09-08T11:46:51.640

@JoKing Well, I should have tested my stuff before. Now it works – Krzysztof Szewczyk – 2019-09-08T12:25:28.060

5

JavaScript, 79 bytes

After a long time I tried to use JS again...

Thanks to @ShadowCat we made it to 79 bytes:

for(i=0,s="";i++<100;s+=(i%5?i%3?i:'Fizz':i%3?'Buzz':'FizzBuzz')+"\n");alert(s)

Old solution, 87 bytes:

for(i=2,s="1";i<101;s+="\n"+["FizzBuzz","Buzz","Fizz",i][(i%3>0)+2*(i++%5>0)]);alert(s)

flawr

Posted 2015-09-24T19:23:54.480

Reputation: 40 560

I recommend dropping the semi-colon at the end. Also I just used conditionals i%5?i%3?i:'Fizz':i%3?'Buzz':'FizzBuzz' and I got 79 bytes, so I recommend trying that. I would also avoid s="1" and just start i=1,s="" to save an extra byte – ShadowCat7 – 2015-09-24T20:44:55.223

1I was working on a ?: solution but I was not able to get it to work before you commented=) Thank you very much! (Honestly I am still proud of my array indexing solution=P) – flawr – 2015-09-24T20:50:50.833

A trailing newline is acceptable, but a leading newline is not. I don't like this rule, but it's a rule nevertheless – edc65 – 2015-09-24T21:16:34.120

77: change starting part i=s="". 76 using ES6 and template string for newline – edc65 – 2015-09-24T21:42:54.693

75: i recomment this for(i=0,s="";i++<100;s+=((i%3?'':'Fizz')+(i%5?'':'Buzz')||i)+"\n");alert(s), because it saves 6 – Nina Scholz – 2015-09-29T12:00:20.740

@NinaScholz Thanks! I am no more updating as there is another JavaScript version that is way shorter, by ETHproductions

– flawr – 2015-09-29T15:29:19.570

5

Befunge-93, 82 81 bytes

I'm sure this could be golfed, but I think this is a good start.

1+:::3%:#v_"zziF"v>*|>25*,:"!"3*`#@_
v _v#:%5\<   ,,,,<^ >^
<  >\"zzuB",,,,   ^ .#

Try it in this online interpreter.


Attempts that didn't work

1+:::3%: #v_"zziF" v>*#v_>25*,:"!"3*`#@_
v _v#:%5\ <>#,,,,,#<^  >.^
<  >\"zzuB"^        ^

Tries to combine the printing of Fizz and Buzz. Ends up at 88 bytes.

Vertical rendition of the above

Forgot about newlines. 122 bytes. Ick. Without newlines it would be 122-41=81 bytes. Welp.

El'endia Starman

Posted 2015-09-24T19:23:54.480

Reputation: 14 504

5

SQL (PostgreSQL flavour), 107 bytes

SELECT(array[n||'','Fizz','Buzz','FizzBuzz'])[1+(n%3=0)::int+(n%5=0)::int*2]FROM generate_series(1,100)a(n)

Same sort of logic as my R answer

MickyT

Posted 2015-09-24T19:23:54.480

Reputation: 11 735

5

bc, 83 bytes

Undeclared variables are zero by default, so i=0 can be omitted. The three line breaks are required.

for(;++i<101;){if(!i%15)"FizzBuzz
"else if(!i%5)"Buzz
"else if(!i%3)"Fizz
"else i;}

r3mainer

Posted 2015-09-24T19:23:54.480

Reputation: 19 135

5

Bash, 85 81 78 74 72 71 bytes

for((;i++<100;j=i%3&2|i%5/4)){
o=($i Buzz Fizz FizzBuzz)
echo ${o[j]}
}

Thanks to @Neil for saving 4 bytes!
Thanks to @manatwork for saving 3 bytes!
Thanks to @primo for saving 2 bytes!

Try it online!

Dennis

Posted 2015-09-24T19:23:54.480

Reputation: 196 637

for i in {1..100}\n{for((;100>i++;)){ – primo – 2018-11-21T14:59:29.650

1@primo Thanks! Found a way to save one more. – Dennis – 2018-11-21T23:05:58.373

5

Haskell, 105 97 bytes

main=mapM(putStrLn.f)[1..100]
a%b=a`rem`b<1
f n|n%15="FizzBuzz"|n%3="Fizz"|n%5="Buzz"
f n=show n

I'm kinda new to Haskell, so any advice would be appreciated!

Avery Glitch

Posted 2015-09-24T19:23:54.480

Reputation: 51

first line could be main=mapM(print . f)[1..100] – jkabrg – 2015-09-25T11:34:30.777

You can write all the guards of f in a single line: f n|n%15="FizzBuzz"|n%3="Fizz"|n%5="Buzz". – nimi – 2015-09-25T15:21:40.670

I count 96 bytes. If you write f 3++f 5 instead of "FizzBuzz", you can save two more. Also, henkma on anarchy golf has 82 somehow.

– Lynn – 2015-09-26T22:12:01.027

1

I posted an 85 byte answer.

– Lynn – 2015-09-27T14:45:10.233

5

Fortran, 213 bytes

character(len=8)::o
do i=1,100
if(mod(i,15)==0)then;write(*,*)'FizzBuzz'
elseif(mod(i,3)==0)then;write(*,*)'Fizz'
elseif(mod(i,5)==0)then;write(*,*)'Buzz'
else;write(o,'(i8)')i;write(*,*)adjustl(o)
endif;enddo;end

Not as graceful as the golf languages. I could save bytes using print instead of write, but print indents 1 space without a format specifier which would increase the byte count instead. Likewise I lose bytes printing the number because Fortran doesn't like left-justified output for numbers. I didn't bother sticking it all on one line as newlines and semicolons are both 1 byte -- no savings.

casey

Posted 2015-09-24T19:23:54.480

Reputation: 551

5

TI-BASIC, 59 bytes

For(X,1,ᴇ2
int(ln(gcd(X,15→J              ;[3 divides X] + [5 divides X]
X
If J
sub("FizzBuzz",7-2gcd(X,3),4J
Disp Ans
End

Or at the same length:

For(X,1,ᴇ2
gcd(X,15→J
X
If ln(J
sub("FizzBuzz",5^(J=5),4int(ln(J
Disp Ans
End

Both programs use the fact that ⌊ln(3)⌋ = ⌊ln(5)⌋ = 1 and ⌊ln(15)⌋ = 2.

There could be another byte to golf off somewhere, but I can't find it. By comparison, here's the naïve approach at 67 bytes:

For(X,1,ᴇ2
"Fizz
If fPart(X/3:X
If not(fPart(X/5:"Buzz
If not(fPart(X/15:"FizzBuzz
Disp Ans
End

TI-BASIC's quirks lengthen the program in two ways:

  • TI-BASIC needs two bytes to encode every lowercase letter other than i (which represents the imaginary unit).
  • Empty strings are not supported: sub("FizzBuzz",5,0 and ""+"Buzz" both throw errors.

lirtosiast

Posted 2015-09-24T19:23:54.480

Reputation: 20 331

Wouldn't moving X to the 2nd to last line shave a byte? (Disp X?) (For the seond one) – Conor O'Brien – 2015-09-29T00:08:32.353

Here are my suggested revisions (I don't have my calculator handy, so I'm not sure if it remains the same.) – Conor O'Brien – 2015-09-29T00:49:02.527

Ohhhh I see. The Ans functionality sometimes confuses me. Sorry if I sounded pretentious ;) – Conor O'Brien – 2015-09-29T00:53:21.457

I found a byte on the "naive" solution by storing "Buzz" to Str2 then "Fizz" to Str1 at the beginning of the loop, leaving "Fizz in Ans so lines 5 and 6 can use Str2 and Str1+Str2.

Also by my byte counts following token size here: http://tibasicdev.wikidot.com/one-byte-tokens

The naive solution is 70 bytes to the above 69. Between the optimal solutions, the one that does not precompute int(ln( on gcd(X,15 should be the smallest at 60 bytes to 61 for the other.

– TiKevin83 – 2019-11-22T16:34:50.023

5

Bash + coreutils, 41 bytes

seq 100|sed 5~5cBuzz|sed 3~3s/[^B]*/Fizz/

You can't seem to do better without cheating: the 12-byte answers on that server simply invoke its gs2 interpreter with a 1-byte FizzBuzz program...

Lynn

Posted 2015-09-24T19:23:54.480

Reputation: 55 648

5

GolfScript, 37 bytes

100,{)..3%!'Fizz'*\5%!'Buzz'*+\or n}/

brendan

Posted 2015-09-24T19:23:54.480

Reputation: 51

5

Transact-SQL, 163 143 124 110 bytes

This requires SQL Server 2012+

(thanks MickyT for the unnamed variable and the IIF suggestions, changed to muqo's GOTO loop instead of WHILE)

declare @ int=1a:print iif(@%3*@%5>0,ltrim(@),iif(@%3=0,'Fizz','')+iif(@%5=0,'Buzz',''))set @+=1IF @<101GOTO a

Formatted and explained:

declare @ int=1                      --@ is a valid variable name
a:                                   --shorter than WHILE
    print iif(@%3*@%5>0, ltrim(@),   --ltrim is shorter than explicit cast
          iif(@%3=0,'Fizz','')       --nest the IIFs
        + iif(@%5=0,'Buzz',''))
    set @+=1
IF @<101 GOTO a

Phrancis

Posted 2015-09-24T19:23:54.480

Reputation: 165

Hello, and welcome to PPCG! Great answer! Can you please add an explanation? – NoOneIsHere – 2016-05-06T02:06:08.947

Sure thing I'll include the ungolfed version, it's just a while loop – Phrancis – 2016-05-06T02:06:59.893

I feel a bit privileged that in many languages you can't use expressions in case statements, but also a bit sad that the Oracle SQL person got fewer bytes... – Phrancis – 2016-05-06T06:15:00.430

@MickyT thanks for the advice! However the way you wrote it produces FiBuzz for 15 and others, just FYI, and the @ number needs to be cast to a string – Phrancis – 2016-05-07T01:19:17.860

@MickyT got it down to 143 thanks to your suggestions! – Phrancis – 2016-05-07T01:34:08.957

Sorry about that, SQL fiddle didn't want to play for me.. – MickyT – 2016-05-07T01:34:51.200

You may want to try the last iif with no cast and a NULL instead of an empty string, otherwise the concat can be replaced with +. don't know what i was thinking when I first suggested it. also char may work if the cast can't be removed. – MickyT – 2016-05-07T01:53:50.583

I think casting to char might violate the rules of the contest, since it will pad with spaces when the number is less characters than the specified amount... – Phrancis – 2016-05-07T03:55:22.037

@MickyT the iif(@ % 3 * @ % 5 <> 0, @ , null) worked great, wow – Phrancis – 2016-05-07T03:59:58.263

Using + instead of concat made it to where the cast would be needed again, so based on character count I stayed with concat – Phrancis – 2016-05-07T04:08:01.107

1Good work, but this needs more golfing. Use GOTO, not WHILE. Skip CONCAT because you need to force only @ to be a string, so just enclose it in LTRIM or something. Use + for the Fizz and Buzz IIFs, and nest that in the IIF for the other numbers. Remove as many spaces as possible. I can get your entry down to 110 doing all that. – Muqo – 2016-07-21T13:59:29.513

1Code and explanation didn't match. Took the opportunity to edit in @Muqo's suggestions. – BradC – 2018-04-19T17:32:10.927

4

8086 machine code, 70 68 62 bytes

00000000  31 c0 40 50 89 c2 89 e5  68 0a 24 d4 05 75 06 68  |1.@P....h.$..u.h|
00000010  7a 7a 68 42 75 89 d0 d4  03 75 06 68 7a 7a 68 46  |zzhBu....u.hzzhF|
00000020  69 89 d0 83 fc fa 75 08  d4 0a 86 c4 0d 30 30 50  |i.....u......00P|
00000030  b4 09 89 e2 cd 21 89 ec  58 3c 64 75 c5 c3        |.....!..X<du..|
0000003e

How it works:

            |   org 0x100
            |   use16
31 c0       |       xor ax, ax
40          |   aa: inc ax
50          |       push ax
89 c2       |       mov dx, ax
89 e5       |       mov bp, sp
68 0a 24    |       push 0x240a
d4 05       |       aam 5
75 06       |       jnz @f
68 7a 7a    |       push 0x7a7a
68 42 75    |       push 0x7542
89 d0       |   @@: mov ax, dx
d4 03       |       aam 3
75 06       |       jnz @f
68 7a 7a    |       push 0x7a7a
68 46 69    |       push 0x6946
89 d0       |   @@: mov ax, dx
83 fc fa    |       cmp sp, -6
75 08       |       jne @f
d4 0a       |       aam 10
86 c4       |       xchg al, ah
0d 30 30    |       or ax, 0x3030
50          |       push ax
b4 09       |   @@: mov ah, 0x09
89 e2       |       mov dx, sp
cd 21       |       int 0x21
89 ec       |       mov sp, bp
58          |       pop ax
3c 64       |       cmp al, 100
75 c5       |       jne aa
c3          |       ret

user5434231

Posted 2015-09-24T19:23:54.480

Reputation: 1 576

This is very nice and very clean work! Using the stack is quite elegant! Technically PUSH immediate was not available on the 8086, so this is really 80186+ machine code. Also, not sure if it's allowed or not, but this does show leading 0's on single digit numbers (01 02 Fizz 03, etc). – 640KB – 2019-08-28T01:04:05.917

4

05AB1E, 29 bytes

тLʒ"Fizz"D'ÒÖ™DŠ«)¬ÑD5ås3å«è,

Try it online!

To my surprise (or my incapability to use the search function) there was no 05AB1E answer to this question.

Explanation

тLʒ"Fizz"D'ÒÖ™DŠ«)¬ÑD5ås3å«è,
тL                            # push [1,...,100]
  ʒ                           # for each...
   "Fizz"                      # Push Fizz (didn't find a way to shorten this one sadly)
         D                     # Duplicate
          'ÒÖ™                 # Push Buzz
              D                # Duplicate
               Š               # Move top item on the stack two slots down
                «              # Concatenate the top items (Results in FizzBuzz)
                 )             # Wrap stack to array
                  „           # Get Divisors of N
                    D5å        # Does 5 divide it?
                       s3å     # Does 3 divide it?
                          «    # Concatenate top two items
                           è,  # Gets item in the array at the index of the concatenated divisors (indexing wraps around) and prints  

Datboi

Posted 2015-09-24T19:23:54.480

Reputation: 1 213

4

Fortran, 188 bytes

do i=1,100
if(mod(i,3)==0.and.mod(i,5)==0)then;print'(a)','fizzbuzz'
elseif(mod(i,3)==0)then;print'(a)','fizz'
elseif(mod(i,5)==0)then;print'(a)','buzz'
else;print'(i0)',i
end if;enddo;end

lewisfish

Posted 2015-09-24T19:23:54.480

Reputation: 41

2Welcome to PPCG! – Martin Ender – 2017-08-03T15:32:43.580

1...change print'(a)' etc. to print* to save 16 bytes – roblogic – 2019-04-05T14:49:04.297

I never used print* as it prints the characters with a space or two before hand, thus it doesn't match the required format. – lewisfish – 2019-04-15T14:09:38.537

4

Befunge-93, 61 bytes

1+::::3%|>.#_:"c"`#@_55+,
,,:,,0\v>"ziF"
,:,,$01>>5%#v_"zuB",

Try it online!

Decided to come back to this and make it conform to specification while shaving some bytes off. Look, no extra spaces!

Jo King

Posted 2015-09-24T19:23:54.480

Reputation: 38 234

4

Brain-Flak, 474 470 446 438 420 412 bytes

-18 bytes thanks to Nitroden!

-8 thanks to Wheat Wizard

(((()()()()()){}){}){({}[(()())]((((())))))}{}{({}<>)<>({}<>)<>({}()()<>)<>}<>{}{}{([{}]())({()<(({}())()){(<{}>)((((()()()())())((((({}{}){})[()]){}){}()))){({}<>)<>}}{}{(<{}>)(((((()()()())({})){}())(({})({}())({}{})))){({}<>)<>}}>}{}[()]){([](<>))<>((()()()()()){}){(({}<({}())>)){({}[()])<>}{}}{}<>([{}()]{}<>)<>{({}<>)(<>)}}{}(<>)<>}<>{}{{({}((((()()()){}){}){}){}<>)<>}({}(()()()()()){}<>)<>}<>{({}<>)<>}<>

Try it online!

Gosh, it's nice to finally check this off my to-do list.

Explanation:

Brain-Flak is obviously not very good at getting the modulo of numbers, so I bypassed this by pushing all the elements first.

(((()()()()()){}){}) Push 20
{ Loop 20 times
    ({}
    [(()())]    Push a 2 to represent a Buzz
    ((((()))))  Push 4 1s
    ) And decrement loop counter
}{} Pop the excess 0
{ Loop over the list of numbers
    ({}<>)<>({}<>)<> Transfer two of the elements to the other stack
    ({}()()<>)<>     And add 2 to the last one
}<>{}{} Pop the excess two elements

Now 1 represents normal numbers, 2 represents Buzz, 3 is Fizz and 4 represents FizzBuzz. Initially I just pushed the values that repeat every 15 numbers 7 times and popped the excess 5, but this way turned out to be slightly shorter.

{ Loop over each element
    ([{}]()) Subtract one from the current element
    ({ Fizz and/or Buzz if num is not 1
        <(({}())())  Subtract 1 and push, twice
        { Push Buzz if num was not 3
            (<{}>)((((()()()())())((((({}{}){})[()]){}){}()))){({}<>)<>}
        }{}
        { Push Fizz if num is not 2
            (<{}>)(((((()()()())({})){}())(({})({}())({}{})))){({}<>)<>}
        }
        >
        ()
    }{}[()]) Push -1 if neither Fizz nor Buzz were pushed
    {
        ([](<>)) Push length of list to other stack
        <>((()()()()()){}) Push 10 as the mod
        Div/mod algorithm
        {(({}<({}())>)){({}[()])<>}{}}{}<>([{}()]{}<>)<>
        Pushes n%10 to output stack and n/10 to the list stack
        { If div is not 0
            ({}<>) Push it to the other stack
            (<>)   Push 0
        }
    }{} Pop excess 0
    (<>)<> Push 0 to other stack to represent a newline
}<>{} Pop extra newline
{ Loop over values
    {
        ({}((((()()()){}){}){}){}<>)<>  Add 48 to every value
    }
    ({}(()()()()()){}<>)<> Turn 0s into newlines
}  Until there's two 0s in a row
<>{({}<>)<>}<> Reverse output

Jo King

Posted 2015-09-24T19:23:54.480

Reputation: 38 234

1Fizz in 44 bytes – Nitrodon – 2018-05-16T18:00:42.337

1Buzz in 44 bytes – Post Rock Garf Hunter – 2018-07-19T04:00:55.080

4

Perl 6, 109 93 bytes

for$i(1..100){if($i%3<1){say"Fizz"};if($i%5<1){say"Buzz"};if($i%3>0&&$i%5>0){say$i};say"\n";}

There might be some more golfing potential here.
Takes advantage the fact that 0 is the only way x % y can be less than 1 (thanks to Alex. A for shaving off 4 bytes with this) and Perl 6's say keyword.

ASCIIThenANSI

Posted 2015-09-24T19:23:54.480

Reputation: 1 935

I didn't spot this somehow... Sorry, If you'd like to adopt some of the ideas in my answer you can save more bytes! say is available in Perl 5 too for free (http://meta.codegolf.stackexchange.com/q/273#answer-274) and it includes a newline (which would further shorten mine by 5 bytes). Happy to remove mine (since it's newer than yours).

– Dom Hastings – 2015-09-24T20:26:12.677

4

Lua, 88 86 bytes

Saved 2 bytes thanks to @Mauris

I'm sure this can be golfed more, any suggestions are welcome.

for i=1,100 do n=(i%3<1 and"Fizz"or"")..(i%5<1 and"Buzz"or"")print(n~=""and n or i)end

Nico A

Posted 2015-09-24T19:23:54.480

Reputation: 2 390

Try i%3<1 and i%5<1? – Lynn – 2015-09-26T22:25:09.157

82 bytes: for i=1,100 do s=('Fizz'):sub(i%3*5)..('Buzz'):sub(i%5*5)print(s==''and i or s)end – Lynn – 2015-09-27T21:56:24.357

I posted a 72-byte solution that ties the record on anarchy golf.

– Lynn – 2015-09-27T22:19:51.457

4

PowerShell, 59 58 bytes

Original used array selection, but was one byte longer than a minor variation of TimmyD's answer

old: 1..100|%{@($_,"Fizz","Buzz","FizzBuzz")[!($_%3)+2*!($_%5)]}

new: 1..100|%{"Fizz"*!($_%3)+"Buzz"*!($_%5)+"$_"*!!($_%3*$_%5)}

The only real trick involving use of double negation to make anything non-zero a 1 while leaving a zero a zero.

I would have left this as a comment on TimmyD's answer, but I lack the reputation.


EDIT: GAH! I see, now, that the original array implementation was naive insofar as my not having read through the other solutions and realizing that it was already in use ... multiple times over. I leave it here, but shamefacedly admit my ignorance.

Forty3

Posted 2015-09-24T19:23:54.480

Reputation: 341

Welcome to PPCG! Nice to see another PowerShell user around. Neat trick with the array-indexing, and further proof that PowerShell is nothing if not flexible. Note that, in this particular instance, you don't need to prepend the @ symbol, since PowerShell treats any comma-separated list as an array, saving a byte on that guy and making the two the same length. See an update on my answer as well, incorporating other suggestions. – AdmBorkBork – 2015-09-25T13:08:56.573

4

SWI-Prolog, 109 bytes

forall(between(1,100,I),((I mod 3<1,print('Fizz');1=1),(I mod 5<1,print('Buzz');I mod 3>0,print(I);1=1),nl)).

Fatalize

Posted 2015-09-24T19:23:54.480

Reputation: 32 976

How is this supposed to be run? I would suggest +X:-print(X)., but it appears this is run from the REPL. Néanmoins, I mod 3>0,print(I);1=1 can become I mod 3<1;print(I). Also anagol has 87 bytes (in anagol, the m/0 predicate is run) for FizzBuzz http://golf.shinh.org/p.rb?FizzBuzz#Prolog

– user41805 – 2019-12-14T10:51:05.163

4

Beam, 307 288 bytes

And now for the longest solution. I think I could compress this a bit more, but the brain is getting a little fried. I'm pretty happy I got it working though. Rearranged it slightly to gain a few.

+P'++P'++P'''''''>`++ \/+)@'''''>`+++++++)@' \
v```P'''----(+++++++++/+/P+++'L@@++(+++++`<''/
>'p-`n'''''''>`++++++++/
^    >'P'p-``n'         >'p-``n'''''''''''>`++++++)@'''''''>`++ \
^       <    >p:L''p-``       >''P``v
^      Hu```P-p'''L@++++++++++LP+p  <``P+++++''L@@+++++@++(+++++/

var ITERS_PER_SEC = 100000;
var TIMEOUT_SECS = 50;
var ERROR_INTERRUPT = "Interrupted by user";
var ERROR_TIMEOUT = "Maximum iterations exceeded";
var ERROR_LOSTINSPACE = "Beam is lost in space";

var code, store, beam, ip_x, ip_y, dir, input_ptr, mem;
var input, timeout, width, iterations, running;

function clear_output() {
document.getElementById("output").value = "";
document.getElementById("stderr").innerHTML = "";
}

function stop() {
running = false;
document.getElementById("run").disabled = false;
document.getElementById("stop").disabled = true;
document.getElementById("clear").disabled = false;
document.getElementById("timeout").disabled = false;
}

function interrupt() {
error(ERROR_INTERRUPT);
}

function error(msg) {
document.getElementById("stderr").innerHTML = msg;
stop();
}

function run() {
clear_output();
document.getElementById("run").disabled = true;
document.getElementById("stop").disabled = false;
document.getElementById("clear").disabled = true;
document.getElementById("input").disabled = false;
document.getElementById("timeout").disabled = false;

code = document.getElementById("code").value;
input = document.getElementById("input").value;
timeout = document.getElementById("timeout").checked;
 
code = code.split("\n");
width = 0;
for (var i = 0; i < code.length; ++i){
 if (code[i].length > width){ 
  width = code[i].length;
 }
}
console.log(code);
console.log(width);
 
running = true;
dir = 0;
ip_x = 0;
ip_y = 0;
input_ptr = 0;
beam = 0;
store = 0;
mem = [];
 
input = input.split("").map(function (s) {
  return s.charCodeAt(0);
 });
 
iterations = 0;

beam_iter();
}

function beam_iter() {
while (running) {
 var inst; 
 try {
  inst = code[ip_y][ip_x];
 }
 catch(err) {
  inst = "";
 }
 switch (inst) {
  case ">":
   dir = 0;
   break;
  case "<":
   dir = 1;
   break;
  case "^":
   dir = 2;
   break;
  case "v":
   dir = 3;
   break;
  case "+":
   ++beam;
   break;
  case "-":
   --beam;
   break;
  case "@":
   document.getElementById("output").value += String.fromCharCode(beam);
   break;
  case ":":
   document.getElementById("output").value += beam;
   break;
  case "/":
   dir ^= 2;
   break;
  case "\\":
   dir ^= 3;
   break;
  case "!":
   if (beam != 0) {
    dir ^= 1;
   }
   break;
  case "?":
   if (beam == 0) {
    dir ^= 1;
   }
   break;
  case "|":
   switch (dir) {
   case 2:
    dir = 3;
    break;
   case 3:
    dir = 2;
    break;
   }
   break;
  case "_":
   switch (dir) {
   case 0:
    dir = 1;
    break;
   case 1:
    dir = 0;
    break;
   }
   break;
  case "H":
   stop();
   break;
  case "S":
   store = beam;
   break;
  case "L":
   beam = store;
   break;
  case "s":
   mem[beam] = store;
   break;
  case "g":
   store = mem[beam];
   break;
  case "P":
   mem[store] = beam;
   break;
  case "p":
   beam = mem[store];
   break;
  case "u":
   if (beam != store) {
    dir = 2;
   }
   break;
  case "n":
   if (beam != store) {
    dir = 3;
   }
   break;
  case "`":
   --store;
   break;
  case "'":
   ++store;
   break;
  case ")":
   if (store != 0) {
    dir = 1;
   }
   break;
  case "(":
   if (store != 0) {
    dir = 0;
   }
   break;
  case "r":
   if (input_ptr >= input.length) {
    beam = 0;
   } else {
    beam = input[input_ptr];
    ++input_ptr;
   }
   break;
  }
 // Move instruction pointer
 switch (dir) {
  case 0:
   ip_x++;
   break;
  case 1:
   ip_x--;
   break;
  case 2:
   ip_y--;
   break;
  case 3:
   ip_y++;
   break;
 }
 if (running && (ip_x < 0 || ip_y < 0 || ip_x >= width || ip_y >= code.length)) {
  error(ERROR_LOSTINSPACE);
 }
 ++iterations;
 if (iterations > ITERS_PER_SEC * TIMEOUT_SECS) {
  error(ERROR_TIMEOUT);
 }
}
}
<div style="font-size:12px;font-family:Verdana, Geneva, sans-serif;">Code:
    <br>
    <textarea id="code" rows="6" style="overflow:scroll;overflow-x:hidden;width:90%;">+P'++P'++P'''''''>`++ \/+)@'''''>`+++++++)@' \
v```P'''----(+++++++++/+/P+++'L@@++(+++++`<''/
>'p-`n'''''''>`++++++++/
^    >'P'p-``n'         >'p-``n'''''''''''>`++++++)@'''''''>`++ \
^       <    >p:L''p-``       >''P``v
^      Hu```P-p'''L@++++++++++LP+p  <``P+++++''L@@+++++@++(+++++/
 </textarea>
        <br>
        <input id="run" type="button" value="Run" onclick="run()">
        <input id="stop" type="button" value="Stop" onclick="interrupt()" disabled="disabled">
        <input id="clear" type="button" value="Clear" onclick="clear_output()">&nbsp; <span id="stderr" style="color:red"></span>
    </p>Output:
    <br>
    <textarea id="output" rows="6" style="overflow:scroll;width:90%;"></textarea>
    <br>Input:
    <br>
    <textarea id="input" rows="1" style="overflow:scroll;overflow-x:hidden;width:90%;"></textarea>
    <p>Timeout:
        <input id="timeout" type="checkbox" checked="checked">&nbsp;
        <br>    </div>

Explanation

+P'++P'++P'''''''>`++ \
v```P'''----(+++++++++/

Initializes the program, presetting values in memory
Memory 0, value 1, count incrementer
Memory 1, value 3, div 3 decrementer
Memory 2, value 5, div 5 decrementer
Memory 3, value 99, loop decrementer

>'p-`n
     >'P'p-``n        
             >p:L''p-`` 

Gets value from Memory 1, decrements it, sets Store to 0. If value <> 0 change direction down, otherwise pass though.
Do the same with Memory 2. Finally if it gets down there, print out the current counter from memory 0.

                       /+)@'''''>`+++++++)@' \
                       +/P+++'L@@++(+++++`<''/
      '''''''>`++++++++/

Prints Fizz and resets memory slot 1 to 3.

                    >'p-``n'''''''''''>`++++++)@'''''''>`++ \

                                 ``P+++++''L@@+++++@++(+++++/

Another div 5 checker to catch FizzBuzzs. Prints out Buzz and resets memory slot 2 to 5.

                              >''P``v
       Hu```P-p'''L@++++++++++LP+p  <

Increments the counter, prints a newline, decrements the loop counter and exits if required.

MickyT

Posted 2015-09-24T19:23:54.480

Reputation: 11 735

4

MATLAB, 94 bytes

for i=1:100 t=mod(i,3);f=mod(i,5);s=[(t&f)*num2str(i) ~t*'Fizz' ~f*'Buzz' ''];disp(s(s>0));end

So this new code is a slight improvement on the one below. Rather than using arrayfun() which is quite costly in characters as it requires 'UniformOutput','false' to get it to work, I have simply made it a for loop - because the range of numbers is hard coded, there is no need to use a function as I had done in my last edit. Removing it from the function saves another 10 characters.

This does basically the same thing, but rather than making all the strings first, in makes them one by one in a for loop and displays them. This actually also means char() only has to be used once (in the other one it was used a second time to display everything). Having the loop means I can use variables to store the results of mod(i,3) and mod(i,5) so they don't need calculating twice. The nonzeros() function has also now been removed, instead opting for storing to a variable then only printing anything which is not equal to zero. This solution when you run it also doesn't print ans= before the first line.

Thanks to @flawr for the tips, saved 4 bytes.


Old code:

MATLAB, 118 bytes

char(arrayfun(@(x) char(nonzeros([(mod(x,3)&&mod(x,5))*num2str(x) ~mod(x,3)*'Fizz' ~mod(x,5)*'Buzz'])'),1:100,'Un',0))

A bit of fun with multiplying strings with scalars. Basically the output of ~mod(x,5) and ~mod(x,3) are multiplied by 'Fizz' and 'Buzz' respectively which produces either zeros (blanks) or one or both of the words. (mod(x,3)&&mod(x,5))) is basically when the number is neither a multiple of 3 nor 5 which is multiplied by the number as a string to get either zeros or the number.

These are then concatenated into an array which then has all of the zeros removed using nonzeros() and then resulting array transposed to be in the right direction for conversion to a character string.

Finally once all numbers have been processed by arrayfun(), the resulting cell array of arrays is passed to char() which converts it to a cell array of strings. Because there is no ; at the end of the string, the output is dumped to the console.


It might be possible to make it smaller, I'm looking ;)

Tom Carpenter

Posted 2015-09-24T19:23:54.480

Reputation: 3 990

I like your solution! Just some hints, you can use [s,''] instead of char(s) (I'd add that in the disp.) Then if you have arguments like UniformOutput it usually suffices to just write U or Un (just as many letters needed for discerning the different possible arguments) and instead of true,false you can use 1,0 (or for true any finite value bigger but zero). This also means instead of s~=0 you can use ~s or if this does not work s>0 or s<0 depending on the application. – flawr – 2015-09-25T22:50:45.987

@flawr Thanks for the tips. I hadn't realised that appending '' converted to a char string. I've saved 4 more bytes. Added the '' to the s=[ ] bit as it does the same as adding it in disp() but without the cost of the extra []. Also the s>0 was a bit of a duh moment on my part! – Tom Carpenter – 2015-09-26T04:29:59.503

There is a Tipps for golfing in Matlab (and linked there one for golfing in Octave) might be worth reading (and expanding=). Happy golfing=)

– flawr – 2015-09-26T10:04:24.597

4

Pip, 32 31 bytes

LhP J["Fizz""Buzz"]X!*++i%^35|i

Try it online!

Explanation

LhP J["Fizz""Buzz"]X!*++i%^35|i
                                 Preinitialized variables: h=100, i=0
Lh                               Loop 100 times:
                          ^35     Split 35 into a list of digits: [3 5]
                      ++i         Pre-increment i (thus starting at 1, not 0)
                         %        Mod (vectorizing); our list is now [i%3 i%5]
                    !*            Map logical not to that list (1 if mod was 0, else 0)
     ["Fizz""Buzz"]               List containing Fizz and Buzz 
                   X              Repeat string (vectorizing)
                                  Our two items are now:
                                   "Fizz" if i is divisible by 3, "" otherwise
                                   "Buzz" if i is divisible by 5, "" otherwise
    J                             Join that list into a single string
  P                          |i   Logical or with i, and print

DLosc

Posted 2015-09-24T19:23:54.480

Reputation: 21 213

4

Python 3, 59 bytes

Based on @feersum's answer.

for i in range(100):print(i%3//2*"fizz"+i%5//4*"buzz"or-~i)

Jean Nassar

Posted 2015-09-24T19:23:54.480

Reputation: 41

4

C (83 characters)

Because misusing a (POSIX conformant) printf is not that bad, after all:

i;main(){while(++i<101)printf(i%3?i%5?"%2$d\n":"%s\n":"Fizz%s\n",i%5?"":"Buzz",i);}

Stefano Sanfilippo

Posted 2015-09-24T19:23:54.480

Reputation: 1 059

4

SQL (Oracle), 112 108 bytes

SELECT NVL(DECODE(MOD(LEVEL,3),0,'Fizz')||DECODE(MOD(LEVEL,5),0,'Buzz'),LEVEL)FROM DUAL CONNECT BY LEVEL<101

db<>fiddle here

MT0

Posted 2015-09-24T19:23:54.480

Reputation: 3 373

1''||LEVEL can be simple replaced with level – Dr Y Wit – 2019-08-28T14:15:55.633

4

Gol><>, 40 bytes

`e2RFL5%zR"zzuB"L3%zR"zziF"lQlRoaoC|LN|;

Updated for 0.4.0! I'm still tinkering with loops and trying to figure out how to do things best, but this is looking good so far.

Try it online.

Explanation

`e            Push 'e', or 101
2RF ... |     Execute F for loop twice - the first time activates the loop, and the
              second time updates it. This effectively makes the loop start from 1
L5%z          Push 1 if loop counter % 5 is 0, else 1
R"zzuB"       Push "Buzz" (top of stack) number of times
L3%z          Push 1 if loop counter % 3 is 0, else 1
R"zziF"       Push "Fizz" (top of stack) number of times
lQ ... |      If the stack is not empty...
  lRo         Output stack
  ao          Output newline
  C           Continue for loop
LN            Otherwise, print loop counter with newline

;             Terminate program

As we can see, there's a lot of abuse of R, which pops the top of the stack and executes the next instruction that many times.

Sp3000

Posted 2015-09-24T19:23:54.480

Reputation: 58 729

That's a smart idea! Mind if I use it? – Conor O'Brien – 2015-10-28T12:16:48.887

4

Seriously, 36 bytes

2╤R`;;3@%Y"Fizz"*)5@%Y"Buzz"*(+;I`Mi

Explanation:

2╤   push the value 10**2 (100)
R       pop a: push range(1,a+1)
`       start function literal
  ;;      duplicate the top of the stack twice
  3       push the value 3
  @       swap the top 2 values
  %       pop a,b: push a%b
  Y       pop a: push 1 if a==0, else 0
  "Fizz"  push the string "Fizz"
  *       pop a,b: push a*b (in this case, "Fizz" repeated b times)
  )       rotate the stack right by one ([a,b,c] -> [c,a,b])
  5@%Y"Buzz"*   Do the same thing as above, but with divisibility testing for 5 and using "Buzz"
  (       rotate the stack left by one
  +       pop a,b: push a+b (string concatenation here)
  ;       dupe top of stack
  I       pop a,b,c: push b if a is truthy, else c (here, a and b are the same string, either "", "Fizz", "Buzz", or "FizzBuzz", and c is the original integer)
`       end function literal
M       pop f,[a]: using each element of [a] as a temporary stack, evaluate f, and push the result
i       flatten [a] (push each value in [a] to the stack, starting from the end to preserve order)

Try it online.

Mego

Posted 2015-09-24T19:23:54.480

Reputation: 32 998

Methinks you need a logical NOT in Seriously. – lirtosiast – 2015-11-10T23:11:17.673

@ThomasKwa Maybe. I was wishing it had one while I was writing this. Seriously has ~, which is unary bitwise negation, which is not quite the same thing. I might add one. – Mego – 2015-11-10T23:13:31.280

4

Perl 6, 46 bytes

say "Fizz"x $_%%3~"Buzz"x $_%%5||$_ for 1..100

Hotkeys

Posted 2015-09-24T19:23:54.480

Reputation: 1 015

2You can remove the spaces after x – Jo King – 2019-01-06T03:27:42.827

4

Javascript, 64 bytes

for(i=0;++i<101;)console.log((i%5?'':'fizz')+(i%3?'':'buzz')||i)

RuteNL

Posted 2015-09-24T19:23:54.480

Reputation: 71

I'm not sure, but I think we allow alert for js output which would save you a few bytes. Nice answer btw. – Maltysen – 2016-05-06T01:43:19.730

1We do allow alert. – Rɪᴋᴇʀ – 2016-05-06T01:48:19.893

1All of the other JS answers on this particular challenge use console.log, except for one that outputs the entire text at once. – ETHproductions – 2016-11-26T15:09:50.523

3

APL, 41 bytes

⊣{⎕←∊(z,⍱/z←0=3 5|⍵)/'Fizz' 'Buzz'⍵}¨⍳100

Tested on GNU-APL (ver 1.7/980M)

Ala'a Mohammad

Posted 2015-09-24T19:23:54.480

Reputation: 51

Do you need the space between ' and ? – Zacharý – 2017-08-03T20:34:47.280

Oh, I haven't used GNU APL in a while, is the needed, since you display directly to STDOUT? – Zacharý – 2017-08-04T22:15:23.457

@Zacharý In GNU-APL monadic 'left tack' discards the value of the right argument. I read it as return nothing (since it points to left). I hope this is the correct way to phrase it. on the other hand, I do not have experience with Dyalog or a ready-setup to play with. – Ala'a Mohammad – 2017-08-06T18:45:49.440

Oh, for some reason I was thinking the return value was not written to STDOUT by default. – Zacharý – 2017-08-06T19:05:29.220

3

TeX, 304 bytes

\documentclass[9pt,a4paper]{article}\pagestyle{empty}\begin{document}\count0=0\count1=0\count3=3\count5=5\loop\advance\count1 by1\count0=0
\ifnum\count1=\count3 Fizz\advance\count3 by3\count0=1\fi\ifnum\count1=\count5 Buzz\advance\count5 by5\count0=1\fi\the\count1

\ifnum\count1<100\repeat\end{document}

Somehow count0 is necessary but I didn't check whether it is zero. It works and I have no idea why.

Leaky Nun

Posted 2015-09-24T19:23:54.480

Reputation: 45 011

I'm assuming that extra newline is there for a reason, but what's the reason? – Stephen – 2017-08-20T00:06:00.257

1@StepHen two newlines is a new paragraph – Leaky Nun – 2017-08-20T00:06:23.247

3

Excel VBA, 88 Bytes

Anonymous VBE immediate window function that takes no input and outputs to the VBE immediate window.

For i=1To 100:o="":o=IIf(i Mod 3,o,"Fizz"):o=IIf(i Mod 5,o,o+"Buzz"):?IIf(o="",i,o):Next

Ungolfed

For i=1To 100                   ''  iterate from 1 to 100
    o=""                        ''  reset out var at each var
    o=IIf(i Mod 3,o,"Fizz")     ''  set the out var to `Fizz` if i Mod 3 = 0
    o=IIf(i Mod 5,o,o+"Buzz")   ''  append `Buzz` to out var if i Mod 5 = 0
    ?IIf(o="",i,o)              ''  If out var is non-empty, output the out var
                                ''      else output i
Next

Worksheet Version, 97 Bytes

Anonymous VBE immediate window function that takes no input and outputs to the range [C1:C100]

[A1:C100]=Array("=ROW()","=IF(MOD(A1,3),,""FIZZ"")&IF(MOD(A1,5),,""BUZZ"")","=IF(B1="""",A1,B1)")

Ungolfed

[A1:A100]="=ROW()"
[B:B]="=IF(MOD(A1,3),,""FIZZ"")&IF(MOD(A1,5),,""BUZZ"")"
[C:C]="=IF(B1="""",A1,B1)"

Subroutine Version, 110 Bytes

Declared Subroutine that takes no input and outputs to the VBE immediate window

Sub F
For i=1To 100
o=""
If i Mod 3=0Then o="Fizz
If i Mod 5=0Then o=o+"Buzz
Debug.?IIf(o="",i,o)
Next
End Sub

Taylor Scott

Posted 2015-09-24T19:23:54.480

Reputation: 6 709

1You can remove o="": and change your first iif to IIf(i Mod 3,"","Fizz") – seadoggie01 – 2018-09-07T20:53:01.237

For the Subroutine version, the () after F isn't optional, and gets added in automatically. Same with the ? in debug. – Selkie – 2019-02-26T18:14:57.307

1

@Selkie, the behavior you are describing is known as autoformatting, and it is generally accepted in this community for VBA and for all languages that exhibit autoformatting, one may post their code from before it is autoformatted. in this case, that would mean that a couple of spaces may be removed, terminal "s dropped, changing print to ? and removal of the () from the Sub declaration. I suggest that you take a look at the Tips for Golfing in VBA page for more info

– Taylor Scott – 2019-02-26T21:30:37.393

3

AppleScript, 104 102 100 bytes

""
repeat with i from 1to 100
result&{"FizzBuzz",i,"Fizz","Buzz"}'s item((i^4mod 15+7)div 4)&"
"
end

If you run it in Script Editor, the result has "quotes" around it. If you run it with osascript, there are no "quotes", but the result ends with an extra blank line.

I steal the technique from Lynn's Lua answer, where the script picks from a list of possible values to print. I use (i^4mod 15+7)div 4 to calculate the index 1, 2, 3, or 4. It's different from Lua's i^2%3+i^4%5*2+1.

In AppleScript, i^4 raises i to 4th power. It returns a real, which is a floating-point number, but the value is equal to the correct integer.

The values of n = i^4mod 15 with i from 1 to 15 are

i = 1   2   3   4   5   6   7   8   9  10  11  12  13  14  15
n = 1   1   6   1  10   6   1   1   6  10   1   6   1   1   0

So n is 0.0 for "FizzBuzz", 1.0 for i, 6.0 for "Fizz", or 10.0 for "Buzz". This pattern continues with i from 16 to 100. I need to map the values 0.0, 1.0, 6.0, 10.0 to a list index; lists in AppleScript start at index 1.

n          = 0.0   1.0   6.0  10.0
(n+2)mod 7 = 2.0   3.0   1.0   5.0
(n+7)div 4 = 1     2     3     4

My 104-byte answer used (n+2)mod 7, but that mapping had 5.0 instead of 4.0, so it needed a list of 5 items, where the extra item 0, cost 2 bytes. My 102-byte answer uses (n+7)div 4. My 100-byte answer deletes 2 extra spaces.

kernigh

Posted 2015-09-24T19:23:54.480

Reputation: 2 615

3

Symbolic Python, 324 bytes

I think I fried my brain making this...

_____=_;_=-~(_==_);___=_**(_*_+_);____=___+___/_+_+_
___=(('%'+`'¬'`[-_])*_)%(___+_,___*_-_*_-_)
___=`_>_`[_>_]+`__`[_*_+_]+___[~-_]*_,___[-_]+`__`[_]+___[~-_]*_
_=_>_
__('____=""'+(';_=-~_;____+=((_%-~-~(_==_)<(_==_))*___[_>_]+(_%-~-~-~-~(_==_)<(_==_))*___[_==_]'+`_____`[_==_]+`_==_`[_==_]+'`_`)+'+`"""
"""`)*____)
_=____

Try it online!

FlipTack

Posted 2015-09-24T19:23:54.480

Reputation: 13 242

3

SNOBOL4 (CSNOBOL4), 137 121 114 bytes

I	X =X + 1
	O =EQ(REMDR(X,3)) 'Fizz'
	O =O EQ(REMDR(X,5)) 'Buzz'
	O =IDENT(O) X
	OUTPUT =O
	O =LT(X,100) :S(I)
END

Try it online!

Explanation:

					;* uninitialized variables start as ''
					;* which is coerced to 0 in computations
I	X =X + 1			;* Increment X
	O =EQ(REMDR(X,3)) 'Fizz'	;* if X mod 3 == 0, O = 'Fizz'
	O =O EQ(REMDR(X,5)) 'Buzz'	;* if X mod 5 == 0, concatenate O and 'Buzz'
	O =IDENT(O) X			;* if O is IDENTical to the empty string,
					;* set O to X
	OUTPUT =O			;* print O
	O =LT(X,100) :S(I)		;* set O to '' and if X < 100, goto I
END

Giuseppe

Posted 2015-09-24T19:23:54.480

Reputation: 21 077

3

Hexagony, 77 76 bytes

=?3})"F\>%'5?\"\B;u;"}/4;d'%<>\g/"!{{\}.%<@>'...<>,}/${;;z;i;z;;$/<>?{$/"./_

Try it online!

Same side length as M L's solution, but a bit smaller.

Expanded:

      = ? 3 } ) "
     . \ > % ' 5 ?
    \ F \ B ; u ; "
   } " / ; d ' % < >
  \ g 4 / ! { { \ } . 
 % < @ . > " ' . < > ,
  } / $ { ; ; z ; i ;
   z ; ; $ / < > ? {
    $ / " . / _ . .
     . . . . . . .
      . . . . . .

Coloured 77 byte version (only difference is the bottom right corner):

enter image description here

  • Green: The general outline of the loop
  • Light Blue: "Fizz" printer
  • Dark Blue: "Buzz" printer
  • Yellow: Number printer
  • Red: Terminator path

How it Works:

Memory Model:

enter image description here

  • Num: The counter
  • Mod: The number we are moduloing(?) with the counter
  • Temp: Our calculation edge
  • Check: The FizzBuzz check

Below I'll be referring to the instructions as they are executed, ignoring no-ops and direction changes.

At the start we execute =?3})"%< which increments the counter (initially 0) and checks whether it is divisible by 3. If so, we branch up and execute "F;i;z;;{ which prints "Fizz" in the check edge and returns to the temp edge.

}?5'%>: Now we check if the number is divisible by 5. If so, B;u;"z;; prints "Buzz" in the check edge (the " is out of place to prevent printing an excess character at termination). If not, we execute an extra instruction to switch to the check edge.

If Fizz and/or Buzz has been printed, the check edge has a leftover "z" in it, else it is 0. If it is a 0, we execute z{{!"'} which puts a z in the check edge and prints the number before returning to the check edge and executing the check again. Now the check edge has a "z" in it no matter what, so we branch to the ?{}g4; which prints a newline.

Finally, d'% checks if the number is divisible by 100. If so, it terminates. Otherwise, it moves to the start of the loop.

Jo King

Posted 2015-09-24T19:23:54.480

Reputation: 38 234

3

12-BASIC, 73 55 50 bytes

FOR I=1TO 100?"FIZZ"*!(I%3)+"BUZZ"*!(I%5)OR I
NEXT

The first code golf program I've written in the language I'm creating.
I should probably avoid code golf while working on it though...

12Me21

Posted 2015-09-24T19:23:54.480

Reputation: 6 110

3

MathGolf, 24 22 bytes

♀{î╕Σ╠δ╕┌╠δ`+Γî35α÷ä§p

Try it online!

Explanation

♀                         Push 100
 {                        Start block
  î                       Push loop counter (1-indexed)
   ╕Σ╠δ                   Decompress "Σ╠" and capitalize to get "Fizz"
       ╕┌╠δ               Decompress "┌╠" and capitalize to get "Buzz"
           `              Duplicate top 2 elements of stack
            +             Add (creating "fizzbuzz")
             Γ            Wrap top 4 elements of stack in array
              î           Push loop counter (1-indexed)
               3          Push 3
                5         Push 5
                 α        Wrap last 2 elements in array
                  ÷       Check divisibility (implicit mapping)
                   ä      Convert from binary to int
                    §     Get array item
                     p    print
                          End block on code end, for loop implicit (100 iterations)

maxb

Posted 2015-09-24T19:23:54.480

Reputation: 5 754

@dzaima Darn, I forgot about that completely. I have however had a capitalization operator in mind for a while. That should add one byte to the solution, but it is not yet implemented. – maxb – 2018-09-12T19:33:42.730

I fixed the capitalization, at the cost of two bytes. – maxb – 2018-09-13T06:58:27.157

3

Julia 1.0, 72 bytes

(n->println([n,"Fizz","Buzz","FizzBuzz"][sum(n.%[1,3,5,5].<1)])).(1:100)

Not the shortest solution possible, but I like the obfuscation. Try it online!

Explanation

We apply an anonymous function (n->...) itemwise .( ) to the range 1:100.

The function body does this (using sample input n=5):

n.%[1,3,5,5]          # Modulo n by each of these numbers                     [0,2,0,0]
.<1                   # Itemwise, is each remainder zero?                     [true,false,true,true]
sum(  )               # Count number of trues in the array                    3
                      # This will be 4 for multiples of 15, 3 for multiples
                      # of 5, 2 for multiples of 3, and 1 for other numbers
[n,"F","B","FB"][  ]  # Index (1-based) into this array                       "Buzz"
println(  )           # Print, with a newline

DLosc

Posted 2015-09-24T19:23:54.480

Reputation: 21 213

3

Javascript, 80 bytes

for(i=1;i<101;i++){console.log(i%3==0?i%5==0?"FizzBuzz":"Fizz":i%5==0?"Buzz":i)}

Jeyanth

Posted 2015-09-24T19:23:54.480

Reputation: 133

To whoever downvoted this; you really should explain why. Especially considering Jey is a new contributor. – Marie – 2019-02-27T19:27:09.550

3

brainfuck, 628 499 bytes

+[>>+>>+++<<[>+>->+<[>]>[<+>-]<<[<]>-]>>>[>>]<[>-[------->+<]>---.[--<+++>]<.-[---<+>]<-..<<<<[-]>>>>>>]<[-]<[-]<[-<+>]>+++++<<[>+>->+<[>]>[<+>-]<<[<]>-]>>>[>>]<[-[++++>---<]>-.++[-----<+>]<+.+++++..<<<<[-]>>>>>>]<[-]<[-]<[-<+>]<<<[[-]>>[-<+>>+<]>>>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>]<[<[->-<]++++++[->++++++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<[-]<[-<+>]<[-]<<[->+<]<]++++++++++.>>[-<+>>+<]-[<-->-----]<++]

This took me WAY too long. It's an extremely naive implementation with two divmods and a printing bit for Fizz and Buzz, as well as an equality check for 100. All in all not really golfed. At all. Not even a little bit. But it was fun, as this was my first ever real brainfuck program.

I started this by purposely not looking at any of the other brainfuck answers, partly so I wouldn't get discouraged, and partly so I wouldn't even subconsciously use any other ideas.

Any feedback or shrinkings are appreciated!

Badly commented source code

Try it online!

ThePlasmaRailgun

Posted 2015-09-24T19:23:54.480

Reputation: 383

1Some quick golfing; There's some leftover whitespace in the code, and all the [-]s can be replaced with ,s (if you're okay with EOF being 0). At least one of the [-]s isn't necessary. The not of the modulo will probably be shorter with forking the movement instead ([>>]<), making sure the tape ends up the same afterwards – Jo King – 2019-02-28T02:26:31.327

1I don't think any of my implementations support EOF as 0, but I am interested in the unnecessary [-] clear cell and the [>>]<. Is there a chance you can suggest an edit? – ThePlasmaRailgun – 2019-02-28T05:35:40.307

596 bytes without whitespace and redundant [-]s. I think you'll find that most implementations use 0 as the EOF, and even the ones that don't usually use -1/255, which is still one byte shorter. I guess there's also no change, but that's rare. I'll work on the [>>]< part – Jo King – 2019-02-28T06:11:40.763

499 bytes. I've changed it to the [>>]< method I mentioned above, and golfed some other parts. I didn't really touch the print as a number part, so you can probably golf something there. – Jo King – 2019-02-28T08:02:09.877

3

Zsh, 105 78 68 66 61 bytes

Try it online!

for i ({1..100})(((i%3))||w=Fizz;((i%5))||w+=Buzz;<<<${w-$i})

-27 using simpler approach
-10 using parameter fallback
-2 thanks to @Dennis - kudos for the bash solution
-5 thanks to @GammaFunction


Original solution, using weird r flag... try it online

for ((;i++<100;));{f=$[i%3>0?0:4] b=$[i%5>0?0:4]
echo ${(r:$f::Fizz:)}${(r:$b::Buzz:)}`((f+b>0))||<<<$i`}

roblogic

Posted 2015-09-24T19:23:54.480

Reputation: 554

1

You don't need the last ; on the first line. A port to Bash takes 70 bytes, thus beating my answer.

– Dennis – 2019-08-28T14:49:53.383

1

Also, you don't need the newline before the last } (which is missing in your answer). Try it online!

– Dennis – 2019-08-28T14:56:20.267

the bash solution still wins for originality.. I couldn't port that crazy for expression to zsh – roblogic – 2019-08-28T15:01:24.417

161, mostly thanks to subshells – GammaFunction – 2019-10-15T02:03:41.867

3

Mouse, 75 bytes

1I:(I.101<^0J:I.3\0=["Fizz"J.1+J:]I.5\0=["Buzz"J.1+J:]J.0=[I.!]"!"I.1+I:)$

Ungolfed:

1 I:               ~ Start a loop index at 1
( I. 101 < ^       ~ While I < 101...
  0 J:             ~ Begin a divisibility indicator at 0
  I. 3 \ 0 = [     ~ If I % 3 == 0
    "Fizz"         ~ Print "Fizz" to STDOUT
    J. 1 + J:      ~ Increment J
  ]
  I. 5 \ 0 = [     ~ If I % 5 == 0
    "Buzz"         ~ Print "Buzz" to STDOUT
    J. 1 + J:      ~ Increment J
  ]
  J. 0 = [         ~ If neither 3 nor 5 divides I
    I. !           ~ Print I to STDOUT
  ]
  "!"              ~ Print a newline
  I. 1 + I:        ~ Increment I
)
$

Alex A.

Posted 2015-09-24T19:23:54.480

Reputation: 23 761

1I'm gonna upvote if you add a cat-program. – flawr – 2015-09-24T20:16:53.123

1@flawr You should submit your own cat program. It will be a game of cat and mouse. – Alex A. – 2015-09-24T20:44:35.950

1@flawr Not quite cat, but I did add a zcat program. – Daniel Wagner – 2015-09-25T02:23:30.093

3

Processing, 74 bytes

This is based on the Java answer by Geobits. I converted it into Processing and since Processing is similar to Java, the code is a lot similar to Geobits'.

for(int i=0;i++<100;)println((i%3<1?"Fizz":"")+(i%5<1?"Buzz":i%3<1?"":i));

user41805

Posted 2015-09-24T19:23:54.480

Reputation: 16 320

8Ah, Processing. Java's willful son, stubbornly insisting that he's going to grow up to be an artist :D – Geobits – 2015-09-24T20:24:44.157

3

Ruby, 82 72 70 68 bytes

based on other answers:

puts (1..100).map{|i|(x=(i%3<1?"Fizz":"")+(i%5<1?"Buzz":""))>""?x:i}

old solution:

(1..100).map{|i|$><<"Fizz"if f=i%3<1
$><<"Buzz"if b=i%5<1
$><<i if !(f||b)
puts()}

Camden Narzt

Posted 2015-09-24T19:23:54.480

Reputation: 141

I posted a 50-byte solution.

– Lynn – 2015-09-27T22:44:34.750

3

Common Lisp, 121

(dotimes(x 100)(flet((d(n)(= 0(mod(1+ x)n))))(princ(cond((d 15)"FizzBuzz")((d 3)"Fizz")((d 5)"Buzz")(t(1+ x)))))(terpri))

Readable:

(dotimes (x 100)
  (flet ((d (n) (= 0 (mod (1+ x) n))))
    (princ (cond ((d 15) "FizzBuzz")
                 ((d 3) "Fizz")
                 ((d 5) "Buzz")
                 (t (1+ x)))))
  (terpri))

nanny

Posted 2015-09-24T19:23:54.480

Reputation: 171

3

Ruby, 59

I wanted to make a Ruby version using the slick modulo/integer-division/string-multiplication trick from feersum's Python answer (though unfortunately Ruby doesn't handle string multiplication the same way, so I spent some bytes on that):

100.times{|i|puts "#{i+1}\r"+"Fizz"*(i%3/2)+"Buzz"*(i%5/4)}

Note that this uses a carriage return \r without a newline. I don't know how portable this is; it works on my Linux and should work on Linux in general, as well as on Mac, but I'm not sure how Windows handles it. Without that, here's a 61-byte version:

100.times{|i|puts ("Fizz"*(i%3/2)+"Buzz"*(i%5/4))[/.+/]||i+1}

Reinstate Monica -- notmaynard

Posted 2015-09-24T19:23:54.480

Reputation: 1 053

You don't need space after puts. – Vasu Adari – 2015-12-07T03:20:31.283

3

Commodore Basic, 87 bytes

1F┌I=1TO100:F=F+1:B=B+1:IFF=3T|?"FIZZ";:F=0
2IFB=5T|?"BUZZ";:B=0
3IFF>0A/B>0T|?I;
4?:N─

Or in "shifted mode" to get both lower- and upper-case letters, but with the byte values of lowercase and uppercase swapped relative to ASCII-1967 (press COMMODORE+SHIFT):

1fOi=1to100:f=f+1:b=b+1:iff=3tH?"Fizz";:f=0
2ifb=5tH?"Buzz";:b=0
3iff>0aNb>0tH?i;
4?:nE

Usual PETSCII-to-Unicode substitutions: = SHIFT+O, | = SHIFT+H, / = SHIFT+N, = SHIFT+E

Commodore Basic doesn't have a "modulus" operation, so I need to use alternate methods to figure out when to print what: keeping a pair of counters turns out to be fewer bytes than dividing and checking for integer-ness. It also doesn't have a true logical "and" (despite the manual saying otherwise), so I need to do an explicit comparison against zero to decide if I should print the plain number.

Mark

Posted 2015-09-24T19:23:54.480

Reputation: 2 099

@DLosc, you can switch into "shifted mode" which gives access to both upper- and lower-case, but with the character positions reversed relative to the ASCII-1967 which people are familiar with (eg. character #65 is lowercase "a" rather than uppercase). – Mark – 2015-09-28T02:27:14.260

3

Minkolang, 50 bytes

"d"[i1+d5%6&"Buzz"0c3%6&"Fizz"I1-3&N6@0gx(O)25*O].

Try it here.

Explanation

"d"[...].        For loop that loops from 0 to 99, then stops
i1+              Loop counter + 1 (so it's 1 to 100)
d5%6&"Buzz"      Divisibility test by 5, skips "Buzz" if not divisible
0c3%6&"Fizz"     Divisibility test by 3, skips "Fizz" if not divisible
I1-              Length of stack minus 1 (0 if there's no Fizz or Buzz)
3&N6@            Output as integer if ^ is 0, skip character output otherwise
0gx(O)           Dump the loop counter and output "Fizz"/"Buzz"/"FizzBuzz"
25*O             Print newline

El'endia Starman

Posted 2015-09-24T19:23:54.480

Reputation: 14 504

3

Jolf, 42 33 31 bytes

Try it here! Replace ƒ with \x9f. I'm stealing ETHproduction's method of fizzbuzzing.

ƒΜz~1d|]"FizzBuzz"?%H340?%H548H

Old version, 42 bytes

γ"Fizz"ƒΜz~1d?mτͺ35H+γζ?m|3Hγ?m|5HΖ"Buzz"H
γ"Fizz"                                     γ = "Fizz"
        Μz~1d                               map 1..100 with the following function
             ?mτͺ35H                        if both 3 and 5 | H
                    +γζ                      return γ + ζ
                       m|3H                 else if 3 | H
                           γ                 return γ
                             ?m|5H          else if 5 | H
                                  Ζ"Buzz"    return ζ = "Buzz"
                                         H  else return H
       ƒ                                    join by newlines

I might be able to golf it down by using the dictionary in Jolf, but who would want to with such a perfect score?

Conor O'Brien

Posted 2015-09-24T19:23:54.480

Reputation: 36 228

3

Python 2 REPL, 54

0;exec"print _%3/2*'Fizz'+_%5/4*'Buzz'or-~_;_+=1;"*100

Based on this answer by feersum. Essentially the same technique, only using Python's underscore variable to save 2 chars at the start.

Tersosauros

Posted 2015-09-24T19:23:54.480

Reputation: 226

You should probably specify this answer as "Python 2 REPL", as opposed to feersum's which is a full program. – Sp3000 – 2016-03-07T02:26:16.513

@Sp3000 Done and done. – Tersosauros – 2016-03-07T02:37:42.240

3

Word VBA, 124 189 bytes

Sub f()
For i=1 To 100
r=""
If i Mod 3=0 Then r="Fizz"
If i Mod 5=0 Then r=r & "Buzz"
If r="" Then r=i
Debug.?r
Next
End Sub

The code breakdown is fairly simple (yay, BASIC).

  1. Loop from 1 to 100

    For i=1 To 100
    
  2. Set a variable to be an empty string

    r=""
    
  3. Check the value on the counter to see if we should set the variable to Fizz

    If i Mod 3=0 Then r="Fizz"
    
  4. Check the counter to see if we need to add Buzz (adding it to an empty string is the same as setting that variable to Buzz)

    If i Mod 5=0 Then r=r & "Buzz"
    
  5. Check to see if the variable is still empty and therefore needs to be set to the counter value

    If r="" Then r=i
    
  6. Prints the results to the immediate window

    t = t & r & vbCr
    

EDIT: Used @Taylor-Scott's suggestions to tighten it up. Relies on the meta discussion about counting characters when your IDE forces whitespace. Specifically the conclusion that if you can paste the code from the answer into the IDE and run it without issues, then you don't have to count the results of autoformatting.

phrebh

Posted 2015-09-24T19:23:54.480

Reputation: 41

Actually, the spacing after paragraphs is just a display thing. The plain text output will not have this spacing. :-) If you could add a code breakdown and explanation, this would have my upvote. – wizzwizz4 – 2016-04-22T16:47:39.400

Yes, those are the words I was looking for. Ta! – phrebh – 2016-04-22T17:57:19.050

+1, as promised! I have however noticed some irritating spaces around certain operators; can those be removed, or is it a language "feature"? – wizzwizz4 – 2016-04-22T19:15:08.677

@wizzwizz4 Unfortunately, those spaces are a limitation of the language. The IDE forces them in there and you can't get around using the IDE. One of the many, many reasons that VBA is not a good candidate for code golf. – phrebh – 2016-04-25T19:03:33.437

@phrebh can you write in a non-IDE e.g. notepad++, textedit, etc. and run as VB? – Rɪᴋᴇʀ – 2016-05-05T21:09:34.037

@phrebh the spaces are a "readability feature" of the VBE, not a limitation of the language AFAIK; I believe the code would still be valid VBA (per language specs) without the extra spaces that the VBE puts in. – Mathieu Guindon – 2016-05-07T01:43:22.040

You can drop quite a few bytes by following the tips that the community has outlined here, - of note you should consider outputting via Debug.? rather than to the document - using this you should be able to get this down to 110 bytes or less

– Taylor Scott – 2017-12-07T07:56:15.457

The IDE force-converts Debug.? to Debug.Print – Selkie – 2019-02-25T22:53:07.143

@Selkie Yes, but as pointed out by Taylor Scott, the entered number of characters is what matters. – phrebh – 2019-02-27T22:10:56.400

3

Vim, 66, 57 56 keystrokes

i1<esc>qqYp<C-a>q98@q3Gqy:s/\d*/Fizz<CR>3j@yq@y5Gqz:s<CR>ABuzz<esc>5j@zq@z

Further golfing, and explanation on the way.

James

Posted 2015-09-24T19:23:54.480

Reputation: 54 537

A bit too late, but apparently this doesn't output correctly: Try it online!

– user41805 – 2017-05-16T09:47:13.010

2

Befunge, 65 bytes

_1+::3%^>55+,:"c"`#@
>"zuB"vv.#,,:,,<
|!:%5\ _:!"ziF"^
<,,:,,<:|*

Try it online!

James Holderness

Posted 2015-09-24T19:23:54.480

Reputation: 8 298

2

Valyrio, 13 bytes

s∫main [CF]

This is a fairly basic (and slightly unimaginative) answer.

Explanation

C pushes 100 to the stack, which means that ...

F is the FizzBuzz builtin. This was mainly added in as a basic stack based program but got left in as a command and I never got rid of it.

user63571

Posted 2015-09-24T19:23:54.480

Reputation:

2

SmileBASIC, 70 bytes

Printing "Fizz" and "Buzz" is easy, the slightly more difficult part is to only print the number when required. There are basically 2 ways to do this (and they end up being the same length)

1: Print the number when I isn't divisible by 3 or 5

FOR I=0TO 100A=I MOD 3B=I MOD 5?"Fizz"*!A;"Buzz"*!B;STR$(I)*(A&&B)NEXT

2: Print the number if the cursor is at column 0:

FOR I=1TO 100?"Fizz"*!(I MOD 3);"Buzz"*!(I MOD 3);
?STR$(I)*!CSRX
NEXT

In a previous version of SB, % was used for MOD, making the program shorter:

Petit Computer BASIC, 62 bytes

FOR I=0TO 100?"Fizz"*!(I%3);"Buzz"*!(I%5);
?STR$(I)*!CSRX
NEXT

12Me21

Posted 2015-09-24T19:23:54.480

Reputation: 6 110

1The language name should probably be "SmileBASIC 2.x" or something. – snail_ – 2017-02-06T13:39:02.050

2

Javascript, 56 bytes

for(f=0;f++<100;alert(f%5?b||f:b+'Buzz'))b=f%3?'':'Fizz'

Assuming 100 alerts is an acceptable output method.

BTC

Posted 2015-09-24T19:23:54.480

Reputation: 131

Nice answer, but it's already been posted (That one originally used alert as well, but it was changed to console.log because all the other JS answers do the same)

– ETHproductions – 2017-03-22T21:46:24.690

2

Cardinal 217 bytes

%x>+ v  >+++++~M! 8# "buzz"
0    #~0#+++~>M! # V  "fizz"
+ ^jM<  ~        V>#
+       V      > #xV
= 0              V
t ~             >#x
t t       v      V
* =   > #}#}     /
> ^              >}/
                   .

Try it Online

Explanation

%x
0
+
+
= 0
t ~
t t
* =
> ^

Initializes a pointer with an inactive value of 100 and active value of 0

>+ v
   #
^jM<

Loops around, incrementing the active value of the pointer and sending out a duplicate until the active value is equal to the inactive value (100)

  >+++++~M!
~0#+++~>M!

Checks if the value mod 3 or mod 5 is equal to 0

                   # "buzz"
        #        # V  "fizz"
        ~        V>#
        V      > #xV
                 V
                >#x
          v      V
      > #}#}     /
                 >}/
                   .

Uses reflectors and splitters in order to print only numbers that are not divisible by 3 or 5. Printing fizz when divisible by 3 and buzz when divisible by 5.

fəˈnɛtɪk

Posted 2015-09-24T19:23:54.480

Reputation: 4 166

2

Julia, 70 bytes

for i=1:100 println("$(i%3<1?"Fizz":"")$(i%5<1?"Buzz":i%3>0?i:"")")end

Julia has perl-like string formatting. Very nice for challenges like these.

eaglgenes101

Posted 2015-09-24T19:23:54.480

Reputation: 577

2

q/kdb+, 58 56 49 bytes

Solution:

0{$[sum i:0=y mod 3 5;`Fizz`Buzz(&)i;y]}'1+(!)100

Example:

q)0{$[sum i:0=y mod 3 5;`Fizz`Buzz(&)i;y]}'1+(!)100
1
2
,`Fizz
4
,`Buzz
,`Fizz
7
8
,`Fizz
,`Buzz
11
,`Fizz
13
14
`Fizz`Buzz
16
...etc

Explanation:

0{$[sum i:0=y mod 3 5;`Fizz`Buzz where i;y]}'1+til 100  / ungolfed
 {                                         }'           / anonymous function that takes each-left and each-right
0                                                       / this would be parameter 'x' but we dont use it
                                               til 100  / til generates a list of 0..99
                                             1+         / adds 1 to every item in the list, thus 1..100
  $[                 ;                  ; ]             / switch, $[condition;true;false]
            y mod 3 5                                   / modulo operation on input for 3 and 5, mod[1;3 5] = 1 1
          0=                                            / is 0 equal to this result (basically a 'not' operation)
        i:                                              / save in i for later
    sum                                                 / add these, will get 0, 1 or 2. 0 is interpretted as false
                                 where i                / where gives indices where i is true
                      `Fizz`Buzz                        / 2 item list which gets indexed into (and implicitly returned)
                                     y                  / return the input if the condition was false

Notes:

This ^^ is pretty much a q version of the k solution, so I've written in a different way.. unfortunately it's about 50% slower :(

0{(`Fizz;`Buzz;y)(&)(0=a),all a:mod[y;3 5]}'1+(!)100

Here we are indexing into a list of Fizz, Buzz, based on the result of the modulo operation... The k solution style is better.

streetster

Posted 2015-09-24T19:23:54.480

Reputation: 3 635

2

Swift, 97 bytes

for i in 1...100{i%15==0 ?print("FizzBuzz"):i%3==0 ?print("Fizz"):i%5==0 ?print("Buzz"):print(i)}

SaylorTwift2

Posted 2015-09-24T19:23:54.480

Reputation: 121

2

groovy, 55 bytes

Borrows idea from answer by @feersum https://codegolf.stackexchange.com/a/58623

100.times{println'Fizz'*(it%3/2)+'Buzz'*(it%5/4)?:it+1}

kau

Posted 2015-09-24T19:23:54.480

Reputation: 21

Welcome to PPCG! :) – Beta Decay – 2017-09-24T07:21:46.800

2

tinylisp repl, 130 bytes

(d f(q((n # %)(i(e n 100)(q Buzz)(i(disp(i #(i % n(q Buzz))(i %(q Fizz)(q FizzBuzz))))0(f(a n 1)(i #(s # 1)2)(i %(s % 1)4
(f 1 2 4

Try it online! (Note that the repl auto-completes parentheses at the ends of lines; these have been filled in on the TIO version.)

Explanation

It took me a while to realize I could do FizzBuzz in tinylisp, since the language doesn't have strings. However, it does have the Name type, which can be any run of non-whitespace, non-parenthesis characters; and it also has the disp command, which outputs a value followed by a newline. Together with some creative abuse of recursion, we can get the desired output.

We define a function f with three arguments:

  • n is the counter. We will start at 1 and recurse until 100.
  • # is the number of iterations till the next divisible-by-3 number. (Mnemonic: Shift-3)
  • % is the number of iterations till the next divisible-by-5 number. (Mnemonic: Shift-5)

The first thing f does is check whether n is 100. If so, we return Buzz. This value gets passed all the way up the call stack and printed at the end.

If not, we need to use disp to print either the number, Fizz, Buzz, or FizzBuzz, depending on the values of # and %:

  • If # and % are both nonzero (truthy), the number is not divisible by 3 or 5. Display the number, n.
  • If # is nonzero but % is zero, the number is divisible by 5 but not 3. Display Buzz.
  • If # is zero but % is nonzero, the number is divisible by 3 but not 5. Display Fizz.
  • If # and % are both zero, the number is divisible by 3 and 5. Display FizzBuzz.

Since tinylisp does not have an equivalent to Common Lisp's progn, disp'ing something and then returning a value requires a little trickery. Since disp always returns (), which is falsey, we can use the disp call as the condition of an if (i). The true branch will never be evaluated (0 is a convenient placeholder), and we can put the actual return value in the false branch.

This return value is a recursive call. We add 1 to n, and we subtract 1 from # and % unless they are zero, in which case we reset them to (3-1) or (5-1), respectively.

Ungolfed, using the standard library for long names of builtins (TIO):

(load library)

(def fizz-buzz
 (lambda (counter steps-till-fizz steps-till-buzz)
  (if (equal? counter 100)
   (q Buzz)
   (if
    (disp
     (if steps-till-fizz
      (if steps-till-buzz counter (q Buzz))
      (if steps-till-buzz (q Fizz) (q FizzBuzz))))
    (comment Return val of disp is always falsey, so the true branch is never executed)
    (fizz-buzz
     (add2 counter 1)
     (if steps-till-fizz (sub2 steps-till-fizz 1) 2)
     (if steps-till-buzz (sub2 steps-till-buzz 1) 4))))))

(fizz-buzz 1 2 4)

DLosc

Posted 2015-09-24T19:23:54.480

Reputation: 21 213

Ken Thompson: "Thompson:the original LISP... you know I think it's a horrible language. I really do. But, I was struck with the idea of defining very, very low level semantics,... it defines its own interpreter. It's always been a problem when you describe a language to say what constructs it recognizes and what they actually do and [Lisp] was the cleanest, simplest, most recursive, beautiful semantics of a language I've ever seen. Probably even to this day. But, unfortunately, what it describes I think is just a horrible language." tinylisp is a bit less scary IMHO! – roblogic – 2019-08-28T09:41:19.027

2

KoopaScript, 250 characters

def i 1 if \%va is \%vu set a 1;setath b \%va %% 3;setath c \%va %% 5;setath e \%va %% 15;if \%vb is 0 if \%vc not 0 print Fizz;if \%vb not 0 if \%vc is 0 print Buzz;if \%ve is 0 print FizzBuzz;if \%vb not 0 if \%vc not 0 print \%va;setath a \%va + 1

Guide to reading: Don't. Either learn KoopaScript more or less entirely by looking at the code (my documentation isn't that great) or just take my word for it that it works. By the way, KoopaScript is an interpreted language I made (not specifically for this) that runs inside ActionScript 2, and doesn't actually have else statements, or... most of the stuff that makes other examples short. All functions are one line, so this was pretty easy. Here's the GitHub repo.

Jhynjhiruu Rekrap

Posted 2015-09-24T19:23:54.480

Reputation: 61

1This looks like quite the painful programming language to use haha. Welcome to PPCG! :) – James – 2018-03-08T19:55:27.083

Thanks! Yeah, it is a bit painful, but I can't really be bothered to add stuff like arrays. I made a pi approximator and a prime number generator (both very slow), both were quite painful because of the lack of useful functions. – Jhynjhiruu Rekrap – 2018-03-08T20:45:03.557

2

Whitespace, 307 bytes

[S S S N
_Push_0][N
S S N
_Create_Label_LOOP][S S S T N
_Push_1][T  S S S _Add][S N
S _Duplicate][S N
S _Duplicate][S S S T   T   N
_Push_3][T  S T T   _Modulo][N
T   S T N
_Jump_to_Label_FIZZ_if_0][N
S S S N
_Create_Label_RETURN_FIZZ][S N
S _Duplicate][S N
S _Duplicate][S S S T   S T N
_Push_5][T  S T T   _Modulo][N
T   S T T   N
_Jump_to_Label_BUZZ_if_0][N
S S S S N
_Create_Label_RETURN_BUZZ][S S S T  T   S S T   S S N
_Push_100][T    S S T   _Subtract][N
T   S T T   T   N
_Jump_to_Label_EXIT_WITH_ERROR_if_0][N
S T T   T   T   T   N
_Call_Label_PRINT_INT][S S S T  S T S N
_Push_10][T N
S S _Print_as_character][N
S N
N
_Jump_to_Label_LOOP][N
S S T   
_Create_Label_FIZZ][S S S T S S S T T   S N
_Push_70][T N
S S _Print_as_character][S S S T    T   S T S S T   N
_Push_105][T    N
S S _Print_as_character][S S S T    T   T   T   S T S N
_Push_122][S N
S _Duplicate][T N
S S _Print_as_character][T  N
S S _Print_as_character][N
S N
S 
_Return_to_Label_FIZZ_RETURN][N
S S T   T   N
_Create_Label_BUZZ][S S S T S S S S T   S N
_Push_66][T N
S S _Print_as_character][S S S T    T   T   S T S T N
_Push_117][T    N
S S _Print_as_character][S S S T    T   T   T   S T S N
_Push_122][S N
S _Duplicate][T N
S S _Print_as_character][T  N
S S _Print_as_character][N
S N
S S N
_Return_to_Label_BUZZ_RETURN][N
S S T   T   T   T   N
_Create_Label_PRINT_INT][S N
S _Duplicate][S S S T   T   N
_Push_3][T  S T T   _Modulo][N
T   S S T   N
_Jump_to_Label_LOOP_if_0][S N
S _Duplicate][S S S T   S T N
_Push_5][T  S T T   _Modulo][N
T   S S T   N
_Jump_to_Label_LOOP_if_0][T N
S T _Print_as_integer][N
T   N
_Return][N
S S S T N
_Create_Label_RETURN][N
T   N
_Return]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

Can definitely be golfed. If-checks are rather annoying in Whitespace, and I still have to get used to them some more.

EDIT: Fixed TIO version. Will try to golf it some more later.

General explanation in Pseudo-code:

Integer i = 0
Start LOOP
  Increase i by 1
  If i modulo 3 is 0: Call function FIZZ()
  If i modulo 5 is 0: Call function BUZZ()
  If i is 100: Stop program
  Call function PRINT_INT(i)
  Print new-line
  Go to next iteration of the LOOP

function FIZZ():
  Print "Fizz"
  Return

function BUZZ():
  Print "Buzz"
  Return

function PRINT_INT(integer i):
  If i modulo 3 is 0: Return
  If i modulo 5 is 0: Return
  Print i
  Return

Example run:

Command        Explanation                  Stack                 STDOUT    STDERR

SSSN           Push 0                       [0]
NSSN           Create Label_LOOP            [0]

SSSTN          Push 1                       [0,1]
TSSS           Add (0+1)                    [1]
SNS            Duplicate (1)                [1,1]
SNS            Duplicate (1)                [1,1,1]  
SSSTTN         Push 3                       [1,1,1,3]    
TSTT           Modulo (1%3)                 [1,1,1]
NTSTN          Jump to Label_FIZZ if 0      [1,1]
NSSSSN         Create Label_RETURN_FIZZ     [1,1]
SNS            Duplicate (1)                [1,1,1]
SNS            Duplicate (1)                [1,1,1,1]  
SSSTSTn        Push 5                       [1,1,1,1,5]
TSTT           Modulo (1%5)                 [1,1,1,1]
NTSTTN         Jump to Label_BUZZ if 0      [1,1,1]
NSSSSN         Create Label_RETURN_BUZZ     [1,1,1]
SSSTTSSTSSN    Push 100                     [1,1,1,100]
TSST           Subtract (1-100)             [1,1,-99]
NTSTTTN        Jump to Label_EXIT if 0      [1,1]
NSTTTTTN       Call Label_PRINT_INT         [1,1]
 NSSTTTTN      Create Label_PRINT_INT       [1,1]
 SNS           Duplicate (1)                [1,1,1]
 SSSTTN        Push 3                       [1,1,1,3]
 TSTT          Modulo (1%3)                 [1,1,1]
 NTSSTN        Jump to Label_RETURN if 0    [1,1]
 SNS           Duplicate (1)                [1,1,1]
 SSSTSTN       Push 5                       [1,1,1,5]
 TSTT          Modulo (1%5)                 [1,1,1]
 NTSSTN        Jump to Label_RETURN if 0    [1,1]
 TNST          Print as integer             [1]                      1
 NTN           Return                       [1]
SSSTSTSN       Push 10                      [1,10]
TNSS           Print as character           [1]                      \n
NSNN           Jump to Label_LOOP           [1]

SSSTN          Push 1                       [1,1]
TSSS           Add (1+1)                    [2]
SNS            Duplicate (2)                [2,2]
SNS            Duplicate (2)                [2,2,2]    
SSSTTN         Push 3                       [2,2,2,3]    
TSTT           Modulo (2%3)                 [2,2,2]
NTSTN          Jump to Label_FIZZ if 0      [2,2]
NSSSSN         Create Label_RETURN_FIZZ     [2,2]
SNS            Duplicate (2)                [2,2,2]
SNS            Duplicate (2)                [2,2,2,2]
SSSTSTn        Push 5                       [2,2,2,2,5]
TSTT           Modulo (2%5)                 [2,2,2,2]
NTSTTN         Jump to Label_BUZZ if 0      [2,2,2]
NSSSSN         Create Label_RETURN_BUZZ     [2,2,2]
SSSTTSSTSSN    Push 100                     [2,2,2,100]
TSST           Subtract (2-100)             [2,2,-98]
NTSTTTN        Jump to Label_EXIT if 0      [2,2]
NSTTTTTN       Call Label_PRINT_INT         [2,2]
 NSSTTTTN      Create Label_PRINT_INT       [2,2]
 SNS           Duplicate (2)                [2,2,2]
 SSSTTN        Push 3                       [2,2,2,3]
 TSTT          Modulo (2%3)                 [2,2,2]
 NTSSTN        Jump to Label_RETURN if 0    [2,2]
 SNS           Duplicate (2)                [2,2,2]
 SSSTSTN       Push 5                       [2,2,2,5]
 TSTT          Modulo (2%5)                 [2,2,2]
 NTSSTN        Jump to Label_RETURN if 0    [2,2]
 TNST          Print as integer             [2]                      2
 NTN           Return                       [2]
SSSTSTSN       Push 10                      [2,10]
TNSS           Print as character           [2]                      \n
NSNN           Jump to Label_LOOP           [2]

SSSTN          Push 1                       [2,1]
TSSS           Add (3+1)                    [3]
SNS            Duplicate (3)                [3,3]
SNS            Duplicate (3)                [3,3,3]   
SSSTTN         Push 3                       [3,3,3,3]    
TSTT           Modulo (3%3)                 [3,3,0]
NTSTN          Jump to Label_FIZZ if 0      [3,3]
NSST           Create Label_FIZZ            [3,3]
SNS            Duplicate (3)                [3,3,3]
SNS            Duplicate (3)                [3,3,3,3] 
 SSSTSSSTTSN   Push 70                      [3,3,3,3,70]
 TNSS          Print as character           [3,3,3,3]                F
 SSSTTSTSSTN   Push 105                     [3,3,3,3,122]
 TNSS          Print as character           [3,3,3,3]                i
 SSSTTTTSTSN   Push 122                     [3,3,3,3,122]
 SNS           Duplicate (122)              [3,3,3,3,122,122]    
 TNSS          Print as character           [3,3,3,3,122]            z
 TNSS          Print as character           [3,3,3,3]                z
 NSNS          Jump to Label_RETURN_FIZZ    [3,3,3,3]
NSSSSN         Create Label_RETURN_FIZZ     [3,3,3,3]
SSSTSTN        Push 5                       [3,3,3,3,5]
TSTT           Modulo (3%5)                 [3,3,3,3]
NTSTTN         Jump to Label_BUZZ if 0      [3,3,3]
NSSSSN         Create Label_RETURN_BUZZ     [3,3,3]
SSSTTSSTSSN    Push 100                     [3,3,3,100]
TSST           Subtract (3-100)             [3,3,-97]
NTSTTTN        Jump to Label_EXIT if 0      [3,3]
NSTTTTTN       Call Label_PRINT_INT         [3,3]
 NSSTTTTN      Create Label_PRINT_INT       [3,3]
 SNS           Duplicate (3)                [3,3,3]
 SSSTTN        Push 3                       [3,3,3,3]
 TSTT          Modulo (3%3)                 [3,3,0]
 NTSSTN        Jump to Label_RETURN if 0    [3,3]

  Stack contains additional leading [3, but we'll ignore it in this explanation
SSSTN          Push 1                       [3,1]
TSSS           Add (3+1)                    [4]
SNS            Duplicate (4)                [4,4]
SNS            Duplicate (4)                [4,4,4] 
SSSTTN         Push 3                       [4,4,4,3]    
TSTT           Modulo (4%3)                 [4,4,1]
NTSTN          Jump to Label_FIZZ if 0      [4,4]
NSSSSN         Create Label_RETURN_FIZZ     [4,4]
SNS            Duplicate (4)                [4,4,4]
SNS            Duplicate (4)                [4,4,4,4]   
SSSTSTN        Push 5                       [4,4,4,4,5]
TSTT           Modulo (4%5)                 [4,4,4,4]
NTSTTN         Jump to Label_BUZZ if 0      [4,4,4]
NSSSSN         Create Label_RETURN_BUZZ     [4,4,4]
SSSTTSSTSSN    Push 100                     [4,4,4,100]
TSST           Subtract (4-100)             [4,4,-96]
NTSTTTN        Jump to Label_EXIT if 0      [4,4]
NSTTTTTN       Call Label_PRINT_INT         [4,4]
 NSSTTTTN      Create Label_PRINT_INT       [4,4]
 SNS           Duplicate (4)                [4,4,4]
 SSSTTN        Push 3                       [4,4,4,3]
 TSTT          Modulo (4%3)                 [4,4,1]
 NTSSTN        Jump to Label_RETURN if 0    [4,4]
 SNS           Duplicate (4)                [4,4,4]
 SSSTSTN       Push 5                       [4,4,4,5]
 TSTT          Modulo (4%5)                 [4,4,4]
 NTSSTN        Jump to Label_RETURN if 0    [4,4]
 TNST          Print as integer             [4]                      4
 NTN           Return                       [4]
SSSTSTSN       Push 10                      [4,10]
TNSS           Print as character           [4]                      \n
NSNN           Jump to Label_LOOP           [4]

SSSTN          Push 1                       [4,1]
TSSS           Add (4+1)                    [5]
SNS            Duplicate (5)                [5,5]
SNS            Duplicate (5)                [5,5,5] 
SSSTTN         Push 3                       [5,5,5,3]    
TSTT           Modulo (5%3)                 [5,5,2]
NTSTN          Jump to Label_FIZZ if 0      [5,5]
NSSSSN         Create Label_RETURN_FIZZ     [5,5]
SNS            Duplicate (5)                [5,5,5]
SNS            Duplicate (5)                [5,5,5,5]   
SSSTSTN        Push 5                       [5,5,5,5,5]
TSTT           Modulo (5%5)                 [5,5,5,0]
NTSTTN         Jump to Label_BUZZ if 0      [5,5,5]
 NSSTTN        Create Label_BUZZ            [5,5,5]
 SSSTSSSSTSN   Push 66                      [5,5,5,66]
 TNSS          Print as character           [5,5,5]                  B
 SSSTTTSTSTN   Push 117                     [5,5,5,117]
 TNSS          Print as character           [5,5,5]                  u
 SSSTTTTSTSN   Push 122                     [5,5,5,122]
 SNS           Duplicate (122)              [5,5,5,122,122]    
 TNSS          Print as character           [5,5,5,122]              z
 TNSS          Print as character           [5,5,5]                  z
 NSNS          Jump to Label_RETURN_FIZZ    [5,5,5]
NSSSSN         Create Label_RETURN_BUZZ     [5,5,5]
SSSTTSSTSSN    Push 100                     [5,5,5,100]
TSST           Subtract (5-100)             [5,5,-95]
NTSTTTN        Jump to Label_EXIT if 0      [5,5]
NSTTTTTN       Call Label_PRINT_INT         [5,5]
 NSSTTTTN      Create Label_PRINT_INT       [5,5]
 SNS           Duplicate (5)                [5,5,5]
 SSSTTN        Push 3                       [5,5,5,3]
 TSTT          Modulo (5%3)                 [5,5,2]
 NTSSTN        Jump to Label_RETURN if 0    [5,5]
 SNS           Duplicate (5)                [5,5,5]
 SSSTSTN       Push 5                       [5,5,5,5]
 TSTT          Modulo (4%5)                 [5,5,0]
 NTSSTN        Jump to Label_RETURN if 0    [5,5]

... etc. etc.

SSSTN          Push 1                       [99,1]
TSSS           Add (99+1)                   [100]
SNS            Duplicate (100)              [100,100]
SNS            Duplicate (100)              [100,100,100] 
SSSTTN         Push 3                       [100,100,100,3]    
TSTT           Modulo (100%3)               [100,100,1]
NTSTN          Jump to Label_FIZZ if 0      [100,100]
NSSSSN         Create Label_RETURN_FIZZ     [100,100]
SNS            Duplicate (100)              [100,100,100]
SNS            Duplicate (100)              [100,100,100,100]   
SSSTSTN        Push 5                       [100,100,100,100,5]
TSTT           Modulo (100%5)               [100,100,100,0]
NTSTTN         Jump to Label_BUZZ if 0      [100,100,100]
 NSSTTN        Create Label_BUZZ            [100,100,100]
 SSSTSSSSTSN   Push 66                      [100,100,100,66]
 TNSS          Print as character           [100,100,100]            B
 SSSTTTSTSTN   Push 117                     [100,100,100,117]
 TNSS          Print as character           [100,100,100]            u
 SSSTTTTSTSN   Push 122                     [100,100,100,122]
 SNS           Duplicate (122)              [100,100,100,122,122]    
 TNSS          Print as character           [100,100,100,122]        z
 TNSS          Print as character           [100,100,100]            z
 NSNS          Jump to Label_RETURN_FIZZ    [100,100,100]
NSSSSN         Create Label_RETURN_BUZZ     [100,100,100]
SSSTTSSTSSN    Push 100                     [100,100,100,100]
TSST           Subtract (100-100)           [100,100,0]
NTSTTTN        Jump to Label_EXIT if 0      [100,100]                          error

Kevin Cruijssen

Posted 2015-09-24T19:23:54.480

Reputation: 67 575

2

sed, 275 272 270 260 254 249 245 bytes

s/.*/t0u123456789/
:1
s/(tu?(.).*)/\1\n\2/
s/u(.)(t?)(.*)/\1\2u\3\1/
/9u/{s/t(.)/\1t/;s/u//;s/^/u/}
/99/!b1
s/$/\n10/
s/[0-9][05]/&Buzz/g
s/[0369]{2}/&Fizz/g
s/[147][258]/&Fizz/g
s/[258][147]/&Fizz/g
s/[0-9]+([FB])/\1/g
s/\n0/\n/g
s/[^\n]+\n//
q

Try it Online

This is a pure sed script which discards all input, if any, and then prints all the necessary output lines and quits.

Explanation

The script is divided into a sequence of three main parts: 1. Numeral generation; 2. "Fizz/Buzz/FizzBuzz" insertion; and 3. Formatting.

1. Numeral generation (lines 1 through 6)

The purpose of this part is to generate 99 lines containing the base 10 numerals corresponding to numbers 1 through 99. For that, we first set the entire pattern space to the following string:

t0u123456789

We will call the above string our state string. Next, we enter a loop in which each iteration goes like this:

  1. A newline is appended to the pattern space;
  2. A copy of the first numeral character after the "t" in the state string is appended to the pattern space;
  3. A copy of the first numeral character after the "u" in the state string is appended to the pattern space;
  4. The "u" in the state string is moved from its current position to the immediate right of the first numeral character after it or, if a "t" is already in said position, the "u" is instead moved to the immediate right of that "t";
  5. If the "u" in the state string is immediately at the right of the "9" in the state string, the "t" is moved from its current position to the immediate right of the first character after it, and the "u" is moved from its current position to the immediate left of the "0" in the state string;
  6. If there isn't a "99" anywhere in the pattern space (i.e., the loop has not finished its job of generating all the 99 lines), control goes back to line 2 (label :1) and so this enumeration of procedures is repeated from step 1; otherwise, control flow continues into the next line.

2. "Fizz/Buzz/FizzBuzz" insertion (lines 7 through 11)

The purpose of this part is to append "Fizz" immediately after each two-digit numeral in the pattern space which corresponds to a number which is a multiple of 3 but not of 5; to append "Buzz" immediately after each two-digit numeral in the pattern space which corresponds to a number which is a multiple of 5 but not of 3; and to append "FizzBuzz" after each two-digit numeral in the pattern space which corresponds to a number which is a multiple of both 3 and 5. This is how the computations go:

  1. We append a newline followed by "10" to the pattern space.
  2. Next, we search for all substrings of the pattern space formed by a digit between 0-9 on the left and either a 0 or a 5 on the right. We insert "Buzz" into the pattern space immediately after each such substring;
  3. Finally, we insert "Fizz" into the pattern space immediately after each substring which matches either of the following criteria:
    • Substrings formed by two digits which may be 0, 3, 6, or 9;
    • Substrings formed by a digit which is either 1, 4 or 7 on the left and a digit which is either 2, 5 or 8 on the right;
    • Substrings formed by a digit which is either 2, 5 or 8 on the left and a digit which is either 1, 4 or 7 on the right.

3. Formatting (lines 12 through 15)

This part is straight forward. Here we remove all of the following substrings from the pattern space:

  1. Every contiguous sequence of numeral characters on the immediate left of a "F" or a "B";
  2. All 0's on the immediate right of a newline character;
  3. All characters from the beginning of the pattern space up to and including the first newline character (remember that the state string is still there and there's a newline immediately before the first output numeral).

And then sed just prints the final contents of the pattern space and calls it quits.

lucasb

Posted 2015-09-24T19:23:54.480

Reputation: 451

2

///, 198 bytes

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

Try it online! Try it interactively!

Conor O'Brien

Posted 2015-09-24T19:23:54.480

Reputation: 36 228

2

Ada (GNAT), 298 bytes

with Ada.Text_IO;use Ada.Text_IO;procedure T is begin for I in Integer range 1..100 loop if I mod 15 = 0 then Put_Line("FizzBuzz");elsif I mod 3 = 0 then Put_Line ("Fizz");elsif I mod 5 = 0 then Put_Line ("Buzz");else Put_Line (Integer'Image (I)(2 ..Integer'Image(I)'Last));end if; end loop; end T;

Try it online!

Ungolfed:

with Ada.Text_IO;use Ada.Text_IO;

procedure Test is begin
    for I in Integer range 1 .. 100 loop
        if I mod 15 = 0 then
            Put_Line ("FizzBuzz");
        elsif I mod 3 = 0 then
            Put_Line ("Fizz");
        elsif I mod 5 = 0 then
            Put_Line ("Buzz");
        else
            Put_Line (Integer'Image (I)(2 .. Integer'Image(I)'Last));
        end if;
    end loop;
end Test;

Pretty vanilla, but I didn't see an Ada solution yet. Probably because Ada might just be the worst real-world language to golf with!

LambdaBeta

Posted 2015-09-24T19:23:54.480

Reputation: 2 499

Ada isn't bad, it's more that hardly anyone even knows about it – ASCII-only – 2018-04-18T22:06:35.100

Oh, I love Ada. It is definitely my favourite language. It just sucks for code golf. And yeah, I wish more people knew about it. :) – LambdaBeta – 2018-04-18T22:11:31.083

Well, it can't possibly be as bad as Java :P – ASCII-only – 2018-04-18T22:12:48.803

also on your profile: "am familiar with a majority of commonly used programming languages". which ones exactly? :P – ASCII-only – 2018-04-18T23:05:59.690

207 – ASCII-only – 2018-04-24T09:56:58.167

204 – ASCII-only – 2018-04-24T10:15:28.410

203 – ASCII-only – 2018-04-24T10:16:34.553

You should post that as a separate answer. I didn't abuse Ada2012 as much and forgot to be a child of I/O package. Take credit where its due :) – LambdaBeta – 2018-04-24T12:51:24.190

>

  • I already did :P and 2. I stole the idea from Lynn's Hello World actually
  • < – ASCII-only – 2018-04-24T12:54:56.803

    2

    Forth, 107 101 98 bytes

    : f 101 1 do i 5 mod i 3 mod if dup if i . then else ." Fizz" then 0= if ." Buzz" then cr loop ; f
    

    Ungolfed + close Python equivalent:

    : f              \ def f():
      101 1 do       \     for i in range(1, 101):
        i 5 mod      \         a = i % 5  # Not an actual variable, pushed onto the stack
        i 3 mod      \         b = i % 3
        if           \         if b:      # b is popped
          dup        \             c = a
          if         \             if c:
            i .      \                 print(i, end='')
          then
        else         \         else:
          ." Fizz"   \             print('Fizz', end='')
        then 
        0=           \         a = (a == 0)
        if           \         if a:
          ." Buzz"   \             print('Buzz', end='')
        then
        cr           \         print()
      loop
    ; 
    f                \ f()
    

    Run it!

    Alex

    Posted 2015-09-24T19:23:54.480

    Reputation: 326

    1To Taylor Scott: sorry for deleting the edit. I thought adding another language would be more meaningful – Alex – 2018-04-18T23:25:35.393

    1Alex, while this is definitely a more interesting answer you should feel free to leave multiple responses to challenges. – Taylor Scott – 2018-05-16T14:18:27.220

    2

    APL (Dyalog Unicode), 37 bytesSBCS

    ↑{∨/d←4/0=3 5|⍵:d/'FizzBuzz'⋄⍕⍵}¨⍳100
    

    Try it online!

    ⍳100ɩndices 1…100

    { apply the following anonymous lambda to each of those:

     the argument; e.g. 20

    3 5| the division remainder when that is divided by 3 and 5; e.g. [2,0]

    0= Boolean mask where that is equal to 0; e.g. [0,1]

    4/ replicate those numbers for 4 copies of each; e.g. [0,0,0,0,1,1,1,1]

    d← assign that to d

    ∨/: if any of those are true (OR-reduction); e.g. true:

      d/'FizzBuzz' use d to mask the characters of the string; e.g. "Buzz"

      else:

    ⍕⍵ stringify the argument; e.g. "20"

     mix the list of strings into a matrix, so it prints right  

    Adám

    Posted 2015-09-24T19:23:54.480

    Reputation: 37 779

    2

    Julia, 87 bytes

    z(i)=(f=i .%[3,5] .==0;sum(f)>0 ? foldl(*,["Fizz","Buzz"][f]) : i)
    println.(z.(1:100))
    

    Or we could kind of cheat to drop 3 bytes and use show instead of println. Julia 83 bytes

    z(i)=(f=i .%[3,5] .==0;sum(f)>0 ? foldl(*,["Fizz","Buzz"][f]) : i)
    show(z.(1:100))
    

    or a more legible FP style, poor performing, 91 bytes

    F(x)=foldl(*,["Fizz","Buzz"][x .%[3,5] .==0])
    N(y)=F(y)=="" ? y : F(y)
    println.(N.(1:100))
    

    Julia isn't really made for this, but I had fun thinking about this a bit :).

    caseyk

    Posted 2015-09-24T19:23:54.480

    Reputation: 167

    prod is better than foldr(* – H.PWiz – 2019-11-23T23:45:53.703

    Nice! I didn't think that'd work. Either way my solution is 10s of bytes away from the best Julia one :). – caseyk – 2019-11-23T23:51:41.700

    Sure. My score is here

    – H.PWiz – 2019-11-24T12:25:12.390

    Woah! How'd you do it? Or is that a secret? :) We have a thread that divulged into codegolf on julia discourse! – caseyk – 2019-11-24T13:10:47.043

    Sort of a secret. Although I have discussed julia golfing in a chat room on this site.

    – H.PWiz – 2019-11-24T21:56:41.580

    2

    Javascript 78 (but kinda 58) bytes

    Produces the required string, then prints it. The function that produces the string is 58 bytes, another 20 are used to call console.log.

    z=n=>n?z(n-1)+((n%3?'':'Fizz')+(n%5?'':'Buzz')||n)+'\n':'';console.log(z(100))
    

    Javascript 72 71 bytes (thanks, Jo King!)

    Prints the required lines as it goes. Interweaving console.log with the logic creates a shorter, though less elegant, program.

    z=n=>n&&(z(n-1),console.log((n%3?'':'Fizz')+(n%5?'':'Buzz')||n));z(100)
    

    It can also be written like the following, to the same effect and byte count.

    z=n=>n&&console.log((z(n-1),(n%3?'':'fizz')+(n%5?'':'buzz')||n));z(100) 
    

    De-golfed version:

    z = n =>           // take n as argument
      n && (           // if n is not falsey (e.g. if it is not 0)
        z(n-1),        // use the comma operator to call the previous fizzbuzz
        console.log(   // then print a line
          (n%3 ? '' : 'Fizz')   // 'Fizz' if n is a multiple of 3, otherwise empty
          + (n%5 ? '' : 'Buzz') // Concatenated with 'Buzz' if multiple of 5
          || n         // Or just the number n if the previous string is empty, which implies that n is not divisible by 3 or 5
        )
      );
    z(100)             // Run fizzbuzz from 100
    

    Sebastián Mestre

    Posted 2015-09-24T19:23:54.480

    Reputation: 71

    2

    sed 4.2.2, 129 bytes

    A 400-rep bounty for those who outgolf this solution https://codegolf.meta.stackexchange.com/a/18428/

    s/^/00,/;h
    :
    y/0123456789';,/1234567890;,'/
    /0.$/!{x;G;s/..\n.//}
    h
    s/[05].$/&Buzz/
    s/.*,/Fizz/
    s/.*\WB/B/
    s/[0';]*//gp
    g;/00/d
    t
    

    Try it online!

    s/^/00,/;h
    

    Each number is stored as three characters, the first two store the two-digit padded decimal number, and the last character stores its modulo 3.

    : ... t
    

    In a loop,

    y/0123456789';,/1234567890;,'/
    

    the modulo is cycled, and the number is incremented using transliteration. Each digit is increased modulo 10, then

    /0.$/!{x;G;s/..\n.//}
    

    a simple conditional corrects the first digit on the number if necessary, using the fact each number is stored with exactly 3 characters.

    h
    

    This incremented form is stored in the hold space.

    s/[05].$/&Buzz/
    

    Buzzs are added by looking at the last base-10 digit of the number.

    s/.*,/Fizz/
    

    Fizzs are added by looking at the modulo-3.

    s/.*\WB/B/
    

    There is some cleanup of the number, remove the base-10 digits if needed and

    s/[0';]*//gp
    

    remove leading 0s and the modulo-3 so that it is print-ready, and print it.

    g;/00/d
    

    Finally retrieve the number from the hold space and exit if 00 is present, i.e. 100 has been reached

    user41805

    Posted 2015-09-24T19:23:54.480

    Reputation: 16 320

    2

    Mathematica, 103 86 73 bytes

    With 30 bytes saved thanks to @A Simmons!

    f="Fizz";b="Buzz";Range@100/.{x_/;15∣x->f<>b,x_/;3∣x->f,x_/;5∣x->b}
    

    DavidC

    Posted 2015-09-24T19:23:54.480

    Reputation: 24 524

    You can use g=Divisible instead of the function definition, there's a leading space (and another one right after f<>b,), and you can use x~g~15 instead of x~g~3&&x~g~5. So f="Fizz";b="Buzz";g=Divisible;Range@100/.{x_/;x~g~15->f<>b,x_/;x~g~3->f,x_/;x~g~5->b} – CalculatorFeline – 2016-03-02T16:28:23.010

    You can use f="Fizz";b="Buzz";Range@100/.{x_/;15∣x->f<>b,x_/;3∣x->f,x_/;5∣x->b} for 73 bytes in 67 characters. – A Simmons – 2016-03-02T17:51:12.403

    CatsAreFluffy, It turns out that your code gives incorrect answers for 5 and 100, for example. – DavidC – 2016-03-02T22:28:51.730

    It's a pair of zero width characters right after the g. Here's code for correcting that: FromCharacterCode[ToCharacterCode@#/.{8204|8203->(##&[])}]& (Don't worry, no zero widths here.) – CalculatorFeline – 2016-03-02T22:34:49.053

    2

    JavaScript, 73 bytes

    for(i=s='';i++<100;s+=((i%3?'':'Fizz')+(i%5?'':'Buzz')||i)+"\n");alert(s)
    

    Timwi

    Posted 2015-09-24T19:23:54.480

    Reputation: 12 158

    2

    Nim, 100 76 73 bytes

    for i in 1..100:echo max(["Fizz","",""][i%%3]&["Buzz",""][ord i%%5>0],$i)
    

    Hm... still trying to learn Nim, and I'm thinking there's got to be a better way...

    Sp3000

    Posted 2015-09-24T19:23:54.480

    Reputation: 58 729

    ["Fizz",""][i*i%%3] saves 1. Using ord on a boolean is a useful tip, thanks for that. – primo – 2019-06-19T10:02:39.457

    2

    PHP, 73 71 bytes

    <?for($i=0;$i++<100;)echo$i%3?$i%5?$i:@Buzz:@Fizz.($i%5?"":@Buzz),"
    ";
    

    All the most terrible things. I wanted the wrongheaded ternary to do something magical, but it did not.

    Seth Battin

    Posted 2015-09-24T19:23:54.480

    Reputation: 121

    2

    VB.Net, 147 146 bytes

    Module F
    Sub Main()
    For i=1To 100
    Dim a=i Mod 3,b=i Mod 5
    Console.WriteLine("{0:#}{1:;;Fizz}{2:;;Buzz}",If(a*b>0,i,0),a,b)
    Next
    End Sub
    End Module
    

    It uses the same conditional formatting trick as the C# answer by Pierre-Luc Pineault.

    UPDATED: saved 1 byte thanks to Brian J

    Najkin

    Posted 2015-09-24T19:23:54.480

    Reputation: 171

    you can save a byte by using If instead of IIf. The difference is that IIf is a function that will evaluate both the true and false options, while If is an operator that will only evaluate the option it needs. Functionally doesn't make a difference in this case, but does save a character. – Brian J – 2015-09-25T13:13:26.153

    2

    Ceylon, 368 144 123 96 bytes

    shared void z(){for(i in 1..100){print(["FizzBuzz","Buzz","Fizz",i][(i%5).sign*2+(i%3).sign]);}}
    

    Here we have the ungolfed original of 368 bytes:

    shared void fizzBuzz() {
        for(i in 1..100) {
            if(3.divides(i)){
                 if(5.divides(i)) {
                     print("FizzBuzz");
                 } else {
                     print("Fizz");
                 }
            } else {
                if(5.divides(i)) {
                    print("Buzz");
                } else {
                    print(i);
                }
            }
        }
    }
    

    In Ceylon, Integers are also just objects, so one can call methods on them (like the divides method here).

    1..100 is syntactic sugar for span(1, 100), which is a Range<Integer>, which implements Iterable<Integer>, and can therefore be used with the for loop.

    The print function takes one argument (of type Anything), stringifies it (i.e. if it's an object, calls its .string attribute, if it's null, takes "<null>") and prints it to the standard output.

    Removing whitespace, using a shorter function name, and replacing x.divides(y) by the shorter y%x==0, which is essentially how divides is implemented, gives us this (144 bytes):

    shared void f(){for(i in 1..100){if(i%3==0){if(i%5==0){print("FizzBuzz");}else{print("Fizz");}}else{if(i%5==0){print("Buzz");}else{print(i);}}}}
    

    Of course, this is not the best which is possible ... this uses print and if much too often, and also does the check for divisibility by 5 twice.

    Integers (or Numbers types in general) have also the .sign attribute, which is 1 for positive numbers, 0 for zero, and -1 for negatives. We can use that together with the remainder operator to get a different value for each of the four cases: (i % 5).sign * 2 + (i % 3).sign]. This is 0 for FizzBuzz, 1 for Buzz, 2 for Fizz and 3 for the "plain" case. We can use this as an index of a tuple, coming to this 123-bytes program:

    shared void z() {
        for(i in 1..100) {
            print(["FizzBuzz", "Buzz", "Fizz", i][(i%5).sign*2 + (i%3).sign]);
        }
    }
    

    ([...] is the syntax for both Tuple creation (here a Tuple with element types String, String, String, Integer, formally Tuple<String|Integer, String, Tuple<String|Integer, String, Tuple<String|Integer, String, Tuple<Integer, Integer, Empty>>>, which can be written shorter as [String, String, String, Integer]) and lookup in a Correspondence (and this tuple type implements Correspondence<Integer, String|Integer>).

    Removing the whitespace again gives us this 96 byte program:

    shared void z(){for(i in 1..100){print(["FizzBuzz","Buzz","Fizz",i][(i%5).sign*2+(i%3).sign]);}}
    

    Paŭlo Ebermann

    Posted 2015-09-24T19:23:54.480

    Reputation: 1 010

    2

    awk, 62

    END{for(x="Fizz";i<100;y="Buzz")print++i%15?i%5?i%3?i:x:y:x y}
    

    Pretty sure there's no surprises here.

    Call

    awk 'END{for(x="Fizz";i<100;y="Buzz")print++i%15?i%5?i%3?i:x:y:x y}'
    

    then press Ctrl-D to signal end of input.

    Cabbie407

    Posted 2015-09-24T19:23:54.480

    Reputation: 1 158

    I'm curious if the Ctrl-D should be included in the byte-count. Using a BEGIN block and rearranging the operators a bit adds 1 byte, i.e. BEGIN{for(x="Fizz";i<100;y="Buzz")print++i%3?i%5?i:y:i%5?x:x y} – Robert Benson – 2017-05-30T16:19:09.140

    2

    Go, 162 158 145 143 142 139 bytes

    package main;import."fmt";func main(){for i,p:=1,Println;i<101;i++{s:="";if i%3<1{s+="Fizz"};if i%5<1{s+="Buzz"};if s!=""{p(s)}else{p(i)}}}
    

    Go Playground Link

    Justin Powell

    Posted 2015-09-24T19:23:54.480

    Reputation: 41

    2

    QB64, 102 94 bytes

    FOR i=1TO 100
    o$=MID$("Fizz",i*5MOD 15)+MID$("Buzz",i*5MOD 25)
    IF""<o$THEN?o$ELSE WRITE i
    NEXT
    

    Doesn't work on actual QBasic; see below for why.

    This program has one problem: QBasic/QB64 outputs to an 80x24 window, not a terminal, so the results can't be scrolled back. If you run the above code as-is, all you'll see is the lines from 78 onward. To prove that the code does 1 to 100 correctly, you can add the line SLEEP 1 right before NEXT for a 1-second delay on each iteration.

    Ungolfed code and explanation

    FOR i = 1 TO 100
        index = 5 * (i MOD 3)
        o$ = MID$("Fizz", index)
        index = 5 * (i MOD 5)
        o$ = o$ + MID$("Buzz", index)
        IF "" < o$ THEN
            PRINT o$
        ELSE
            WRITE i
        END IF
    NEXT
    

    On each iteration, we put the appropriate fizzes and buzzes into the string o$, check if it's empty, and output o$ or the number accordingly. The main question is how to get "Fizz" when i is divisible by 3 and "" otherwise. Here are the approaches I tried:

    IF i MOD 3THEN o$=""ELSE o$="Fizz"
    o$="":IF i MOD 3=0THEN o$="Fizz"
    o$=MID$("Fizz",5*(i MOD 3))
    o$=MID$("Fizz",i*5MOD 15)
    

    The approach with MID$ is much shorter. This function takes 3 arguments--string, start index, and number of characters--and returns the appropriate substring. When the third argument is omitted, it takes everything from the start index to the end of the string. Here, when i is exactly divisible, the start index is 0 and we get the whole string; otherwise, it's something larger that's past the end of the string, so MID$ gives "".1

    The other tricky part is printing numbers according to the spec. QBasic's PRINT command outputs positive numbers with leading spaces, which is occasionally useful but usually just annoying. The WRITE command, however, does not add a leading space--perfect for our purposes here.


    1 Strings are 1-indexed in QBasic--i.e., in the string "abcd", a is at index 1 and d is at index 4. This is why I'm multiplying the mod result by 5: MID$("Fizz",4) gives "z". In actual QBasic, 0 isn't a legal index and gives Illegal function call; but in QB64, MID$("Fizz",0) happily returns the whole string instead of complaining.

    DLosc

    Posted 2015-09-24T19:23:54.480

    Reputation: 21 213

    2

    haxe, 110 bytes

    class Main{
      static function main()
        for(i in 1...101)
          Sys.println(i%3<1?"Fizz"+(i%5<1?"Buzz":""):i%5<1?"Buzz":i);
    }
    

    (newlines and indents added for clarity)

    Haxe isn't much of a golfing language … I was trying to do something with enumerators:

    class Main{
      static function main()
        for(i in 1...101)
          Sys.println(
            switch(i){
              case _%3=>0:i%5<1?"FizzBuzz":"Fizz";
              case _%5=>0:"Buzz";
              case _:i;
            }
          );
     }
    

    But 140 bytes. :I

    Aurel Bílý

    Posted 2015-09-24T19:23:54.480

    Reputation: 1 083

    2

    Windows Batch, 166

    @setlocal enableDelayedExpansion&for /l %%N in (1 1 100) do @(set 1=&set/a1/(%%N%%3^)||set 1=Fizz&set/a1/(%%N%%5^)||set 1=!1!Buzz&>nul set 1&&echo !1!||echo %%N)2>nul
    

    This will fail if there are variables with names that begin with 1, but that should never happen under "normal" circumstances.

    dbenham

    Posted 2015-09-24T19:23:54.480

    Reputation: 131

    2

    Go, 130 129 134 bytes

    package main;import."fmt";func main(){for i:=1;i<101;i++{o:="";if i%3<1{o+="Fizz"};if i%5<1{o+="Buzz"};if o==""{Print(i)};Println(o)}}
    

    I wish i had ternary operators...

    Edit: @Dust pointed out that I printed to stderr so my solution actually increased in size :(

    Try it online!

    Kristoffer Sall-Storgaard

    Posted 2015-09-24T19:23:54.480

    Reputation: 489

    I think this prints to STDERR which he said is not allowed. – Dust – 2018-04-19T19:14:28.043

    @Dust you are right, I'll have to revise – Kristoffer Sall-Storgaard – 2018-04-20T07:32:24.727

    2

    O, 53 52 bytes

    I'm sure that there will be a better way to do this. Thanks to kirbyfan64sos for the implicit J.

    "Buzz"JA.*1mrl{.3%{.5%{}{;J}?}{"Fizz"\5%{}{J+}?}?p}d
    

    Try it here

    MickyT

    Posted 2015-09-24T19:23:54.480

    Reputation: 11 735

    52 bytes: "Buzz"JA.*1mrl{.3%{.5%{}{;J}?}{"Fizz"\5%{}{J+}?}?p}d. O has the implicit J variable like Pyth.

    – kirbyfan64sos – 2015-10-01T23:13:10.380

    omg someone other than my mom used O <3 – phase – 2015-11-08T04:09:09.467

    2

    Swift, 75 bytes

    for n in 1...100{print(n%3*n%5>0 ?n:(n%3>0 ?"":"Fizz")+(n%5>0 ?"":"Buzz"))}
    

    Richard G. Nielsen

    Posted 2015-09-24T19:23:54.480

    Reputation: 121

    2

    F#, 129 116 113 111

    Seq.iter(fun x->printfn"%s"(["Fizz";"";""].[x%3]+(if x%5=0 then"Buzz"elif x%3>0 then string x else""))){1..100}
    

    mattnewport

    Posted 2015-09-24T19:23:54.480

    Reputation: 1 579

    2

    D, 130 bytes

    import std.stdio,std.conv;void main(){string x;for(int i;i++<100;x=((i%3?"":"Fizz")~(i%5?"":"Buzz")),writeln(x?x:i.to!string)){};}
    

    Ungolfed:

    module FizzBuzz;
    
    import std.stdio;
    import std.conv;
    
    void main() {
      string x;
      for (
        int i;
        i++ < 100;
        x = ((i % 3 ? "" : "Fizz")
          ~ (i % 5 ? "" : "Buzz")),
        writeln(x ? x : i.to!string)
      ){};
    }
    

    Or, building a string, for 142 bytes,

    import std.stdio,std.conv;void main(){string x,y;for(int i;i++<100;x=((i%3?"":"Fizz")~(i%5?"":"Buzz")),y~=(x?x:i.to!string)~"\n"){};write(y);}
    

    Ungolfed:

    module FizzBuzz;
    
    import std.stdio;
    import std.conv;
    
    void main() {
      string x,y;
      for (
        int i;
        i++ < 100;
        x = ((i % 3 ? "" : "Fizz")
          ~ (i % 5 ? "" : "Buzz")),
        y ~= (x ? x : i.to!string) ~ "\n"
      ){};
      write(y);
    }
    

    cat

    Posted 2015-09-24T19:23:54.480

    Reputation: 4 989

    2

    Hoon, 126 bytes

    %+
    turn
    (gulf [1 100])
    |=
    a/@
    =+
    [=((mod a 3) 0) =((mod a 5) 0)]
    "{?:(-< "Fizz" "")}{?:(-> "Buzz" "")}{?:(=(- [| |]) <a> "")}"
    

    Map over the list [1...100] with the function, interpolating the strings "Fizz" and "Buzz". If both mods are false, then it also interpolates the number.

    This uses the fact that =+ pushes the value to the top of the context, which you can access with - and navigate with -< or -> for head/tail. Unfortunately, it looks pretty ugly because it needs a newline after runes to minimize byte count, along with not having built in operator functions.

    I'm not entirely sure if this counts as a valid entry: It simply returns a list of strings to be printed by the shell, which is optimal. The other way would be to use ~& to print each element as it's mapped over, but it would still be rendered as "Fizz" or "Buzz" (with quotes) since it's a typed print, along with the shell then printing out the entire list anyways since it's the return value.

    RenderSettings

    Posted 2015-09-24T19:23:54.480

    Reputation: 620

    2

    Javascript, 191 bytes

    for(var i=1; i<=100; i++){
      var r = "";
      if( i%15 == 0 ? r = "FizzBuzz" : (i%5 == 0 ? r = "Buzz" : (i%3 == 0 ? r = "Fizz" : r = i)) ){
        console.log(r);
      }
    }
    

    Harshal Sharma

    Posted 2015-09-24T19:23:54.480

    Reputation: 21

    1Welcome to Programming Puzzles & Code Golf. Nice first answer! But please wrap your code into a code-block (indent with 4 spaces or use the button in the editor). Also you should format the header correctly, the common template for this here is ##<language>, <byte count> bytes. Also you have some unnecessary whitespaces in your code which you should remove. – Denker – 2016-03-10T09:59:42.500

    1Nice answer, but the goal of this challenge is to make your answer as short as possible. You can save a ton of bytes by removing all whitespace, and renaming result to r. – ETHproductions – 2016-03-11T20:32:11.757

    2

    XQuery 3, 172 bytes

    declare option output:method "text";string-join(for$x in 1 to 100 return if($x mod 15=0)then"FizzBuzz"else if($x mod 3=0)then"Fizz"else if($x mod 5=0)then"Buzz"else $x,"
    ")
    

    There were only 7 XQuery answers on the whole site, I thought it could at least have its FizzBuzz ! Granted it's not very golfy, in particular when you need to add a 36 bytes preface so that it does not output an XML header.

    I tested it with Saxon-HE's command-line XQuery tool (java net.sf.saxon.Query fizzbuzz.xq), with which I had to replace the w3-defined option declaration with declare option saxon:output "method=text";.

    Aaron

    Posted 2015-09-24T19:23:54.480

    Reputation: 3 689

    2

    Tcl, 136 bytes

    set f {Fizz 3 Buzz 5}
    while {[incr n]<=100} {set s ""
    foreach {m d} $f {if {$n%$d==0} {append s $m}}
    if {$s eq ""} {puts $n} {puts $s}}
    

    This solution, incidentally, is easily extensible to any combination of multiples. See The Smart Person's Mirage golf, where gnibbler posted the same idea (but in Python).

    set iterations 100
    
    set fizzies {
      Fizz 3
      Jazz 4
      Buzz 5
    }
    
    while {[incr n] <= $iterations} {
      set s ""
      foreach {name divisor} $fizzies {
        if {$n % $divisor == 0} {append s $name}
      }
      if {$s eq ""} {puts $n} {puts $s}
    }
    

    Dúthomhas

    Posted 2015-09-24T19:23:54.480

    Reputation: 541

    2

    Oration, 98 bytes

    literally, for i in range(1,100):x=""if i%3 else'Fizz';x+=""if i%5 else "Buzz";print x if x else i
    

    Żáłģó

    Posted 2015-09-24T19:23:54.480

    Reputation: 71

    2

    ROOP, 187 bytes

    1
    V!         !<
    (102)      1|
     e#r3##r5# a|
    #H  #   # Y-<
       N   N  !
    "Fizz""Buzz"
    
       mX  mX
    ### V-->  !
       A V---->
        #
      ' C
     V'e  "\n"
     |# M  #
     <V# #v
     C  A  C
      #X ##
        w
        O#
    

    I will try to explain each section of code:

    V!         !<  Add 1 to each number that goes to the left of the a
               1|  and sends it to the bottom of the V
               a|
               -<
    

    (102)          The 102 falls to the left of the e and each number
     e             that passes over is compared to 102.
    #H             If a number is equal then the H runs and ends the program
    

      #r3#         With each number that goes above the r
        #          the remainder of dividing by 3 is obtained.
       N           The N returns 1 if the number is 0, and 0 otherwise.
    "Fizz"         The string "Fizz" falls and moves to the left of the m.
                   The number is multiplied by the string
       mX          ("" or "Fizz" if it is 0 or 1 respectively)
    ###            The X removes the number when it moves to the right
    
                   The same is done with 5 and "Buzz"
    

       mX  mX      
        V-->      Both strings are concatenated with the A
       A          getting "", "Fizz", "Buzz" or "FizzBuzz"
        #
    

      ' C         The C changes the direction of advance of string, to the left.
      'e          At the same time the "e" compares the string with the empty string.
      #           The single quotes are a vertical literal string.
    

     V            The V and pipes redirects the string to the right of the C
     |            that changes the direction again in order that comes to the left of the A
     <V
     C  A
    

              Y   The original number is converted to a string with Y.
              !
    
    
    
              !   Pipes and teleporters (!) Redirects the string to below the V
         V---->
    

        M         The string falls to the right of the M and multiplies
       # #        with the number previously obtained by the e
        A         The result is above the A
    

          "\n"   The string "\n" falls on the v which makes a copy
        M  #     whenever there is a space below.
          v      The C changes the direction of the string so it goes to the left.
        A  C     It waits to the right of the A
    

        A        The A concatenate all 3 strings, the result is on the w that sends it
      #X ##      to the O representing the output. At the same time the X deletes the string.
        w
        O#
    

    I hope it is comprehensible, English is not my main language.

    DarkPhantom

    Posted 2015-09-24T19:23:54.480

    Reputation: 191

    1

    Mathematica, 61 Bytes

    Heavily inspired by this post on the mathematica stack exchange

    fizzbuzz[#,,fizz,,buzz][[#~GCD~15~Mod~15]]&~Array~100//Colum‌​n
    

    A Simmons

    Posted 2015-09-24T19:23:54.480

    Reputation: 4 005

    This doesn't work properly for me on 10.2, but I assume that's a version variation as {#,,"fizz","fizzbuzz","buzz"}[[#~GCD~15~Mod~11]]&~Array~100//Column does – Mark S. – 2017-08-04T00:42:15.947

    1

    tcl, 72

    time {puts [expr [incr i]%3?$i%5?$i:"":"Fizz"][expr $i%5?"":"Buzz"]} 100
    

    I think it is more golfable, to avoid the repetition of i%5

    demo

    sergiol

    Posted 2015-09-24T19:23:54.480

    Reputation: 3 055

    1

    Plain Javascript (no console.log() & no alert()), 64 bytes

    for(f=b='';f++<100;b+=(f%5?z||f:z+'Buzz')+'\n')z=f%3?'':'Fizz';b
    

    Just copy/paste into any javascript console and hit enter.

    BTC

    Posted 2015-09-24T19:23:54.480

    Reputation: 131

    1

    Lua, 126 bytes

    for i=1,100 do if i%15==0 then print"FizzBuzz"elseif i%3==0 then print"Fizz"elseif i%5==0 then print"Buzz"else print(i)end;end
    

    Josh

    Posted 2015-09-24T19:23:54.480

    Reputation: 1 021

    I don't know Lua too well, but can you remove a few spaces (100do and 0then twice) – Zacharý – 2017-08-03T20:36:40.930

    1

    K, 52 Bytes

    -1@{,/$$[#i:&~.q.mod[x;3 5];`Fizz`Buzz i;x]}'1+!100;
    

    Thanks

    Chromozorz

    Posted 2015-09-24T19:23:54.480

    Reputation: 338

    1

    Turtlèd, 221 bytes

    99;,:[*,l]u[*d{*u,dr}ul' l[ l]ru]u3;[ [ r]l[ ' l]ll"Fizz";]<97:>5[ (*[ r]l[ ' l]ll)(zr)"Buzz";]<104:>[ lll'0rrr[ r]l{*' l{*l}{ l}(9'0l( r"1!")(9"10!"))(8'9)(7'8)(6'7)(5'6)(4'5)(3'4)(2'3)(1'2)(0'1)(!'0):{ l}}[ l]drrrr{zd}]
    

    due to a bug (having two close curly brackets next to each other causes the second one to match to the first ones open bracket), the Try it online version is different for now (I put a space between the two close curly brackets)

    99;,:[*,l]u[*d{*u,dr}ul' l[ l]ru]u3;[ [ r]l[ ' l]ll"Fizz";]<97:>5[ (*[ r]l[ ' l]ll)(zr)"Buzz";]<104:>[ lll'0rrr[ r]l{*' l{*l}{ l}(9'0l( r"1!")(9"10!"))(8'9)(7'8)(6'7)(5'6)(4'5)(3'4)(2'3)(1'2)(0'1)(!'0):{ l} }[ l]drrrr{zd}]
    

    Try it online!

    I might write an explanation if I get time motivated

    Destructible Lemon

    Posted 2015-09-24T19:23:54.480

    Reputation: 5 908

    1

    Ruby, 68 65 bytes

    q='Buzz';(1..100).map &->e{p e%3<1?'Fizz'+(e%5<1?q:''):e%5<1?q:e}
    

    marmeladze

    Posted 2015-09-24T19:23:54.480

    Reputation: 227

    If you've made your program one byte shorter, you'll want to change the header to 64 bytes :) – numbermaniac – 2017-05-16T21:05:55.210

    1Why map &->e{ and not map{|e| ? – daniero – 2017-06-05T21:19:51.273

    1

    REXX 81 Bytes

    f.=""
    f.0="buzz"
    t.=""
    t.0="fizz"
    do i=1 to 100
      f=i//5
      t=i//3
      say overlay(t.t||f.f,i)
    end
    

    theblitz

    Posted 2015-09-24T19:23:54.480

    Reputation: 1 201

    You can golf away four characters by removing the empty strings: f.= instead of f.="". – idrougge – 2017-05-16T11:54:32.220

    I tested f.= on a couple of online interpreters and they didn't like it. – theblitz – 2017-05-16T12:06:34.177

    All right, I only tested it with Regina. – idrougge – 2017-05-16T12:11:01.537

    1

    braingasm, 40 bytes

    The language is coming along nicely. A few recent features allows for a quite decent FizzBuzz, if I may say so myself:

    100[>#3p["Fizz".+]#5p["Buzz".+]z[#:]10.]
    

    Here's how it works:

    100[               One hundred times:
        >                Go to the next cell.
        #3p[             If current cell number is divisble by 3:
            "Fizz".        Print "Fizz".
            +              Increment current cell
        ]
        #5p["Buzz".+]    Same thing for 5 and "Buzz".
        z[               If the current cell is 0 (hasn't been incremented):
          #:               Print current cell number
        ]
        10.              Print a newline
    ]
    

    daniero

    Posted 2015-09-24T19:23:54.480

    Reputation: 17 193

    Hmm nice language... Is there an online interpreter or is it all offline? – Beta Decay – 2017-05-27T16:29:50.273

    @BetaDecay Thanks :) No, nothing online yet. I'm focusing mostly on implementing all my ideas, and to document things once they're a little bit more stable. – daniero – 2017-05-27T16:41:54.540

    1

    Python 2.7, 59 Bytes

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

    Explanation:

    for i in range(100)
    

    This will generate a list of numbers from 1 to 100 and assign it to the i variable.

    print i%3//2*'Fizz'+i%5//4*'Buzz'or i+1
    

    Note that this loop will repeat 100 times, and in each time, the loop will do what this line is commanding.

    Cóemgein

    Posted 2015-09-24T19:23:54.480

    Reputation: 11

    2"This will generate a list of numbers from 1 to 100" I think you meant 0 to 99, otherwise you wouldn't need to use i+1 :) – Aaron – 2017-08-25T15:46:30.850

    You don't need //; with integer arguments, / performs integer division in Python 2. -~i saves an additional byte. https://tio.run/##K6gsycjPM/r/Py2/SCFTITNPoSgxLz1Vw9DAQNOqoCgzr0QhU9VY30hL3S2zqkpdO1PVVN9ES92pFMjJL9Kty/z/HwA

    – Dennis – 2017-08-25T15:49:31.137

    1

    AsciiDots, 152 bytes

     #
    /$""
    \~\
     @\-\
    [=]@*-\
    /@----*-~&
    |0/---*[>]
    |@\<>$_"Buzz"@1)
    |*-~/ /-/
    ||[%]-\>#100)
    v\-*#5*/
    |.//
    | \<>$_"Fizz"@1)
    |/-~/
    @|[%]-\
    0\-*#3/
    *-[+]
    \#1/
    

    Try it online!

    user31415

    Posted 2015-09-24T19:23:54.480

    Reputation: 141

    1

    Python 2, 57 bytes

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

    Not the most beautiful code but it works at least with

    python -c
    

    german_guy

    Posted 2015-09-24T19:23:54.480

    Reputation: 569

    1

    Extremely late answer and for a language that has already a bit too many answers, however, i've not seen a single function answer that actually RETURNS the expected string, instead of printing it to console, so here it is:

    Javascript 73 bytes

    (i=0,r="")=>i>99?r:f(++i,r+=(i%5?i%3?i:'Fizz':i%3?'Buzz':'FizzBuzz')+'
    ')
    

    Brian H.

    Posted 2015-09-24T19:23:54.480

    Reputation: 513

    1

    Funky, 59 bytes

    for(i=1i<100i++)print((("Fizz"*1&!i%3)+("Buzz"*1&!i%5))ori)
    

    Try it online!

    ATaco

    Posted 2015-09-24T19:23:54.480

    Reputation: 7 898

    1

    Acc!!, 260 bytes

    Count i while 100-i {
    i%3/2*2
    Count f while _/2 {
    Write 70
    Write 105
    Write 122
    Write 122
    1
    }
    _+i%5/4*2
    Count b while _/2 {
    Write 66
    Write 117
    Write 122
    Write 122
    1
    }
    Count d while 1-_ {
    (i+1)/10
    Count z while _ {
    Write 48+_
    0
    }
    Write 48+(i+1)%10
    1
    }
    Write 10
    }
    

    Try it online!

    Explanation

    Once you know how Acc!! works, this is pretty straightforward. Count while loops increment their variable from 0 as long as their condition is true. Write takes an ASCII code and outputs the corresponding character. Bare expressions like i%3/2*2 are assigned to the accumulator, _. Division is integer division.

    Our code iterates i from 0 through 99 (thus, the number in question on each iteration is actually i+1).

    • If i%3 is 2 (i.e. i+1 is divisible by 3), we want to print Fizz.
      • Set the accumulator to i%3/2*2, which is 0 if i%3 is less than 2, and 2 otherwise.
      • Loop with condition _/2; we enter the loop iff the accumulator was set to 2 last step.
      • Inside the loop, write Fizz.
      • Set the accumulator to 1, breaking out of the f loop while keeping a record that we Fizzed.
    • If i%5 is 4 (i.e. i+1 is divisible by 5), we want to print Buzz. Same approach as above, except we now add i%5/4*2 to the existing accumulator value to preserve a possible 1 from the Fizz step.
    • If we printed Fizz and/or Buzz, the accumulator is now 1; otherwise, it is 0. If it is 0, we need to output the number.
      • Loop with condition 1-_: we enter the loop iff the accumulator is not 1.
      • Set accumulator to (i+1)/10, the 10's digit.
      • If that result is not 0, write the 10's digit, and set accumulator to 0 to break out of the z loop.
      • Write the 1's digit, (i+1)%10.
      • Set accumulator to 1 to break out of the d loop.
    • Finally, write a newline.

    DLosc

    Posted 2015-09-24T19:23:54.480

    Reputation: 21 213

    1

    APL(NARS), 44, 43, 39 chars 78 bytes

    ⊃{⍱/z←0=3 5∣⍵:⍕⍵⋄∊z/'fizz' 'buzz'}¨⍳100
    

    In practice I follow Adam suggest.

    I had seen other APL solutions, so I copied the way. In the follow APL code, ←A here suppress the output of A.

    ←{⎕←∊{∨/j←0=3 5∣⍵:j/'fizz' 'buzz'⋄⍵}⍵}¨⍳100

    {⎕←∊{∨/j←0=3 5∣⍵:j/'fizz' 'buzz'⋄⍵}⍵⋄⍬}¨⍳100 This above should return at end 100 void list, but it seems they are not showed at last here.

    {⎕←{×+/j←0=3 5∣⍵:⊃,/j/'fiz' 'buz'⋄⍵}⍵⋄⍬}¨⍳100 This just above has one error because fiz and buz should be fizz and buzz

    {⎕←{0<+/j←0=(3 5)∣⍵:⊃,/j/('fiz' 'buz')⋄⍵}⍵⋄⍬}¨⍳100

    :for i:in⍳100⋄{0<+/j←0=(3 5)∣⍵:⊃,/j/('fiz' 'buz')⋄⍵}i⋄:endfor

    RosLuP

    Posted 2015-09-24T19:23:54.480

    Reputation: 3 036

    Ever so slightly golfed (and adding the missing "z"s): ⊃{∨/j←0=3 5∣⍵:∊j/'fizz' 'buzz'⋄⍕⍵}¨⍳100 – Adám – 2017-12-07T23:45:54.843

    1

    C, 152 bytes

    #include<stdio.h>
    #define p printf
    int i,f;main(){while(i++<100){if(i%3==0&&(f=1))p("Fizz");if(i%5==0&&(f=1))p("Buzz");if(f==0||(f=0))p("%d",i);p("\n");}}
    

    Ungolfed one:

    #include<stdio.h>
    #define p printf
    int i,f;
    main()
    {
        while(i++<100)
        {
            if(i%3==0&&(f=1))p("Fizz");
            if(i%5==0&&(f=1))p("Buzz");
            if(f==0||(f=0))p("%d",i);
            p("\n");
        }
    }
    

    Kishan Kumar

    Posted 2015-09-24T19:23:54.480

    Reputation: 427

    This is not ok: main(){while(i++<100){(i%3<1&&p("fizz"))+(i%5<1&&p("buzz"))<1&&p("%d",i);p("\n");} ? – RosLuP – 2017-12-07T19:01:58.850

    1

    C (gcc), 101 bytes

    #define P printf
    main(i){for(i=0;i++<100;P("\n"))(i%3<1&&P("fizz"))+(i%5<1&&P("Buzz"))<1&&P("%u",i);}
    

    It could have one indefinite behavior in the use + operation, the order of evaluation could be swapped. Try it online!

    RosLuP

    Posted 2015-09-24T19:23:54.480

    Reputation: 3 036

    You can change #define P printf to #define P printf( to cut off three bytes.

    – Steadybox – 2017-12-08T07:25:50.853

    94 bytes – Steadybox – 2017-12-08T07:32:41.877

    1

    ><>, 59 bytes

    0v!oo:oo"Fiz"\
    1<oan?*/!?%5$\!?%3;?)"c"::::::+
    o"Buzz"/$0oo
    

    Try It Online

    Prints a trailing newline

    How it works

    0v...
    .<... Initialises the stack with 0
    .....
    
    .....
    1<................;?)"c"::::::+ Increment the counter and duplicate it a looooot
    .....                           End the program if the counter is larger than 99 (ascii value of c)
    
    0..oo:oo"Fiz"\
    .............\!?%3... Check if the counter is divisible by 3 and print Fizz if so
    .....                 Also push a 0 to the stack
    
    .......o         Swap the pushed 0 if it exists (otherwise it swaps two copies of the counter)
    ......./!?%5$... Check if the counter is divisible by 5 and print Buzz if so
    o"Buzz"/$0oo     Also push a 0 to the stack
    
    .......... Multiply the top two values of the stack. 
    ..oan?*... If the counter was divisible by 5 or 3 print the number
    .......... Print a newline and loop around again
    

    As time goes, the stack fills up, with 2 copies of the counter for every Fizz and Buzz and 3 for each FizzBuzz. This is because of the extra copy of the counter that isn't printed and the extra 0s being pushed to the stack.

    Jo King

    Posted 2015-09-24T19:23:54.480

    Reputation: 38 234

    1

    Kotlin, 115 bytes

    fun main(a:Array<String>){(1..100).map{println(when(it%15){0->"FizzBuzz";3,6,9,12->"Fizz";5,10->"Buzz";else->it})}}
    

    Try it online!

    Damiano

    Posted 2015-09-24T19:23:54.480

    Reputation: 131

    1

    face, 152 bytes

    (FizzBuzz%d@
    )\F*,c'Fo>m+*1+m=*m?*m1+m3+m4+m5+11334455$BF"B4$%B"%4$N%"N3:~0?%=+3?=31?w=F4>:3%=+5?=51?w=B4>:5??+p="%c+w="=>:+w=N1>+++1*=55*==4+==1-=+=?=~
    

    Annotated:

    (FizzBuzz%d@
    )
    \F*,c'Fo>               ( obtain data pointer, a number, and stdout )
    m+*1+                   ( counter variable, goes from 1 to 100 )
    m=*m?*                  ( result and temp variables )
    m1+m3+m4+m5+11334455    ( relevant constants )
    $BF"B4$%B"%4$N%"N3      ( get pointers to Fizz, Buzz, %d, and \n )
    :~
        0?                  ( has either Fizz or Buzz been printed? )
        %=+3?=3             ( skip to label 3 if not divisible by 3 )
        1?w=F4>:3           ( otherwise, print "Fizz" )
        %=+5?=51?w=B4>:5    ( same for "Buzz" )
        ??+p="%c+w="=>:+    ( if we didn't print anything, print the number )
        w=N1>               ( print a newline )
        +++1                ( increment the counter )
        *=55*==4+==1-=+=    ( set the result variable to 100-n )
    ?=~
    

    Try it online! (The trailing newline is required on TIO due to a bug that's been fixed in a newer version of face.)

    Doorknob

    Posted 2015-09-24T19:23:54.480

    Reputation: 68 138

    1

    J, 73 Bytes

    }.":`('Fizz'"_)`('Buzz'"_)`('FizzBuzz'"_)@.((0:=3&|)++:@(0:=5&|))"0 i.101
    

    Definitely not the greatest, looking for ways to improve this.

    Explanation:

                                                                     "0 i.101  | To each number from 0 to 100
                                               ((0:=3&|)++:@(0:=5&|))          | 1 if divisble by three, 2 if by 5, 3 if by both
                                             @.                                | Using the result of the previous verb, select a verb from the following gerund
      ":`('Fizz'"_)`('Buzz'"_)`('FizzBuzz'"_)                                  | Apply the appropriate Fizz-Buzz string
    }.                                                                         | Remove the first entry (since we counted 0)
    

    Bolce Bussiere

    Posted 2015-09-24T19:23:54.480

    Reputation: 970

    1

    17, 229 bytes

    17 was made after the challenge was made, but not designed to be any good at it. This code could probably be golfed a bit smaller, but it is a reasonably hard language to do anything with. Golfed version(removed unneeded space and duplicated numbers where useful):

    0{2 #
    1 +
    :
    2 @
    5g ==
    1 +
    0 @}1{2 # 3 % ! 3 *
    2 # 5 % ! 5 *
    + 10 + 0 @}13{42 $ 63 $ 73 : $ $ a $
    0 0 @}15{3f $ 6f $ 73 : $ $ a $
    0 0 @}18{42 $ 63 $ 73 : : : $ $ 3f $ 6f $ $ $ a $
    0 0 @}10{2 # $$ a $
    0 0 @}}777{0 2 @
    0 1 @
    0 0 @}
    

    Ungolfed version:

    0 {
    2 #
    1 +
    :
    2 @
    5g ==
    1 +
    0 @
    }
    
    1 {
    2 # 3 % ! 3 *
    2 # 5 % ! 5 *
    + 10 + 0 @
    }
    
    13 {
    42 $ 63 $ 73 $ 73 $ a $
    0 0 @
    }
    
    15 {
    3f $ 6f $ 73 $ 73 $ a $
    0 0 @
    }
    
    18 {
    42 $ 63 $ 73 $ 73 $ 3f $ 6f $ 73 $ 73 $ a $
    0 0 @
    }
    
    10 {
    2 # $$ a $
    0 0 @
    }
    
    
    777 {
    0 2 @
    0 1 @
    0 0 @
    }
    

    Explanation:

    Block 0: Load value at 2, add 1, duplicate, store at 2, if value == 100 push 1, else 0, add 1, store at 0.

    Block 1: Will only be ran after block zero if value != 100. Load from 2, mod 3, not, times 3. If value at 2 is a multiple of 3 it will be 3, else 0. Same again for 5, add them and 17(looks like 10, but remember it uses base 17) and stores value at 0.

    Block 13(or 20): Will only be run after 1 if value is a multiple of 3, not 5. Push and print ascii values for Fizz\n

    Block 15(or 22): Will only be run after 1 if value is a multiple of 5, not 3. Push and print ascii values for Buzz\n

    Block 18(or 25): Will only be run after 1 if value is a multiple of 3 and 5. Push and print ascii values for FizzBuzz\n

    Block 10(or 17): Will only run after 1 if value is not multiple of 3 or 5. Prints numeric form of value.

    Block 777(or 2149): Like main for C++, first block to be run

    Hugh Williams

    Posted 2015-09-24T19:23:54.480

    Reputation: 51

    1

    kavod, 688 bytes

    535 9}122 2}122 2}105 2}70 2}4 2}122 3}122 3}117 3}66 3}4 3}1 0><-+0>~0~><3 66 9}165.86?<1+>><-+2 0 86 9}478.><-+><5 100 9}165.120?<1+>><-+3 0 120 9}478.><-+<140?><-+><139 9}392.0><-+1+><10#100 158 9}258.162?47.9{.171 9}178.><-+9{.0 8}0 8}8}9}8{9{1+8{>8}9}8{9{>214 9}276.218?241.><-+<7}><<+8{1+8}8}7{196.><-+<1-+<-8{1-9{.-265 9}318.1 273 9}296.9{.-283 9}318.0 1-293 9}296.9{.-303 9}318.307?313.><-9{.1+9{.323?9{.><1+331?359.8}9}8{9{1-345?355.8}9}8{9{325.1+363.1-363.8}9}8{9{><-+9{.0 8}9}8{9{-9{.396?451.><0 406 9}276.457?><-+418 9}421.9{.425?445.10 433 9}178.439 9}421.48+#9{.~0~9{.48+#9{.><-+45#469 9}378.475 9}421.9{.8}~><8}489?499.1-8}>#8{485.><-+8{><8}513?526.1-<8}9}8{9{509.8{+8{~9{.
    

    Try it online!

    Formatted better:

    535 9}122 2}122 2}105 2}70 2}4 2}122 3}122 3}117 3}66 3}4 3}1 0><-+0>~0~><3 66 9}165.86?<1+>>
    <-+2 0 86 9}478.><-+><5 100 9}165.120?<1+>><-+3 0 120 9}478.><-+<140?><-+><139 9}392.0><-+1+>
    <10#100 158 9}258.162?47.9{.171 9}178.><-+9{.0 8}0 8}8}9}8{9{1+8{>8}9}8{9{>214 9}276.218?241.
    ><-+<7}><<+8{1+8}8}7{196.><-+<1-+<-8{1-9{.-265 9}318.1 273 9}296.9{.-283 9}318.0 1-293 9}296.
    9{.-303 9}318.307?313.><-9{.1+9{.323?9{.><1+331?359.8}9}8{9{1-345?355.8}9}8{9{325.1+363.1-363
    .8}9}8{9{><-+9{.0 8}9}8{9{-9{.396?451.><0 406 9}276.457?><-+418 9}421.9{.425?445.10 433 9}178
    .439 9}421.48+#9{.~0~9{.48+#9{.><-+45#469 9}378.475 9}421.9{.8}~><8}489?499.1-8}>#8{485.><-+8
    {><8}513?526.1-<8}9}8{9{509.8{+8{~9{.
    

    Ok so I can only really explain this vaguely, but stacks 2 and 3 hold the strings Fizz and Buzz. The program loops is roughly equivalent to the following code:

    push 0 ;dummy
    
    :fb
        drop
        copy 0
        dup
        call divides 3
        jif not3
            load
            add 1
            copy
            drop
            call puts 2 0
    
        :not3
        drop
    
        dup
        call divides 5
        jif not5
            load
            add 1
            copy
            drop
            call puts 3 0
    
        :not5
        drop
    
        load
        jif cont
            drop
            dup
            call putn
            push 0
    
        :cont
        drop
        add 1
        dup
    
        putc 10
    
        call gt 100
        jnt fb
    
    ret
    

    ...just translated into pseudo-ops codes. Yeah. Then the rest of the program is defining sanity functions.

    Guide to reading

    J 9}N. usually means "call function at N, and return to J afterwards"; 9{. signifies this return.

    Conor O'Brien

    Posted 2015-09-24T19:23:54.480

    Reputation: 36 228

    1

    Wumpus, 49 bytes

    "zzuB"L)=S5%4*&;"zziF"L3%!!4*&;l=]&oL~!?ONL"d"-:.
    

    Try it online!

    Explanation

    I haven't yet found a good way to write compact programs with branching control flow, so I decided to avoid branches altogether for this one (handling conditionals via skipping individual instructions). The program is a single line which is a run in a loop (because the . at the end skips back to the first character).

    We'll be using the stack depth to determine whether Fizz and/or Buzz needs to be printed, so we can't keep the loop counter on the stack. Instead, we'll be using the default register for this (which is initialised to zero).

    "zzuB"   Tentatively push the code points for "Buzz" onto the stack.
    L)=S     Load the loop counter from the register, increment it, and store a
             copy back in the register.
             I'll call the loop counter for this iteration i.
    5%       Compute i % 5 to test divisibility by 5.
    4*       Multiply by 4. This gives 0 if 5 divides i, and some n ≥ 4 if it doesn't.
    &;       Discard that many values from the stack. Discarding from an empty 
             stack does nothing, so if 5 doesn't i, we get rid of "Buzz",
             otherwise, we do nothing.
    
             The code for "Fizz" is similar:
    "zziF"   Push the code points for "Fizz".
    L3%      Compute i % 3.
             This time, we can't just discard n ≥ 4 values, but we have to
             discard exactly 4 values, otherwise we might get rid of the "Buzz".
    !!       Double logical NOT. Gives 0 for 0 and 1 for positive values.
    4*       Multiply by 4. Now we've got 0 if 3 divides i and 4 otherwise.
    &;       Discard that many values to get rid of "Fizz" if 3 doesn't divide i.
    l        Push the stack depth D.
    =]       Make a copy for later and shift it to the bottom of the stack.
    &o       Print D characters from the top of the stack. If any of "Fizz" or
             "Buzz" were left on the stack, this prints them. Otherwise, D = 0
             and this does nothing.
    L~       Load i and put it underneath D.
    !?O      If D = 0, print i (in decimal). Otherwise, i remains on the stack.
    N        Print a linefeed.
    L"d"-    Compute i-100. This is zero when we want to end the program.
    :        Compute i/(i-100). When we've reached i = 100, this terminates the
             program due to the attempted division by zero. Otherwise, this
             leaves some junk value X on the stack.
    .        Jump to (0, X), emptying the stack. But since it's impossible to
             go out of bounds in Wumpus, the coordinates will automatically be
             taken modulo the grid dimensions. Since the grid is only one row
             tall, the y-coordinate becomes X%1 = 0, so regardless of X, this
             always jumps back to the beginning of the program.
    

    Martin Ender

    Posted 2015-09-24T19:23:54.480

    Reputation: 184 808

    1

    Visual Basic .NET (Mono), 151 bytes

    Module M
    Sub Main
    Dim i,s
    For i=1To 100
    s=""
    s=IIf(i Mod 3,s,"Fizz")
    s=IIf(i Mod 5,s,s+"Buzz")
    Console.WriteLine(IIf(s="",i,s))
    Next
    End Sub
    End Module
    

    Try it online!

    Taylor Scott

    Posted 2015-09-24T19:23:54.480

    Reputation: 6 709

    1

    uBASIC, 106 bytes

    Something tells me that Else statements may not be working exactly as intended on TIO - if you can get something of the form of IfS$=""Then?IElse?S$ to work please let me know so I can update my answer.

    0ForI=1To100:S$="":IfIMod3=0ThenS$="Fizz":IfIMod5=0ThenS$=S$+"Buzz"
    1IfS$=""Then?I
    2IfS$<>""Then?S$
    3NextI
    

    Try it online!

    Taylor Scott

    Posted 2015-09-24T19:23:54.480

    Reputation: 6 709

    1

    Yabasic, 108 bytes

    Yet Another answer.

    For i=1To 100
    S$=""
    If!Mod(i,3)Then S$="Fizz"Fi
    If!Mod(i,5)Then S$=S$+"Buzz"Fi
    If S$=""Then?i Else?S$Fi
    Next
    

    Try it online!

    Taylor Scott

    Posted 2015-09-24T19:23:54.480

    Reputation: 6 709

    1

    Husk, 35 bytes

    m§Ysλṁ!⁰₇ḣ3)ḣ100
    ¶Σfm%⁰NC2¨¶¶¶⌈iΩZu
    

    Try it online!

    I feel like I'm missing some opportunities for cleverness here. Like, I'm not really pleased with that lambda sitting there on the first line and having to be manually closed. But anyway, here we are.

    Explanation

    I'll explain the second line first. It's a function TNum -> [[TChar]] that maps

    1 -> []
    2 -> ["","","Fizz"]
    3 -> ["","","","","Buzz"]
    

    It works like this:

    ¶Σfm%⁰NC2¨¶¶¶⌈iΩZu
             ¨¶¶¶⌈iΩZu --The compressed string "\n\n\n\nFiBuzz"
           C2¨¶¶¶⌈iΩZu --cut; the list ["\n\n", "\n\n", "Fi", "Bu", "zz] 
       m%⁰N            --nats mod input, i.e, with input 3, [1,2,0,1,2,...]
      fm%⁰NC2¨¶¶¶⌈iΩZu --filter;so grab (1) nothing, (2) pairs 135, (3) pairs 1245
     Σfm%⁰NC2¨¶¶¶⌈iΩZu --concat;now at (1) [] (2) ["\n\nFizz"] (3) ["\n\n\n\nBuzz"]
    ¶Σfm%⁰NC2¨¶¶¶⌈iΩZu --split by newlines to return claimed result
    

    Next, the lambda in the first line. It has type TNum -> [TChar]; given an integer, it returns "", "Fizz", "Buzz", or "FizzBuzz" as appropriate. In detail:

    λṁ!⁰₇ḣ3)
         ḣ3  --heads; the list [1,2,3]
        ₇ḣ3  --call 2nd line with map overflow: [[],["","","Fizz"],["","","","","Buzz"]]
     ṁ!⁰₇ḣ3  --index the lambda argument to each list (modularly) and concat the results
    

    And pulling it together:

    m§Ysλṁ!⁰₇ḣ3)ḣ100 
        λṁ!⁰₇ḣ3)      --"","Fizz","Buzz",or"FizzBuzz"
       s              --string representation of the number
     §Ysλṁ!⁰₇ḣ3)      --apply both and take max; "" < numeric strings < alphabet
    m§Ysλṁ!⁰₇ḣ3)ḣ100  --map across [1,..,100]
    

    Then Husk's default output style for an object of type [[TChar]] turns out to be just what we want.

    Sophia Lechner

    Posted 2015-09-24T19:23:54.480

    Reputation: 1 200

    This could have been -3 bytes if we didn't need to hardcode it for 100 lines! Ah well. – Sophia Lechner – 2018-03-23T23:48:09.210

    1

    TIS, 573 + 48 = 621 bytes

    Code (573 bytes):

    @0
    MOV ANY DOWN
    MOV ANY RIGHT
    @1
    MOV ANY DOWN
    ADD DOWN
    MOV ANY DOWN
    ADD DOWN
    MOV ANY LEFT
    MOV LEFT DOWN
    ADD DOWN
    @2
    SUB 101
    JLZ C
    HCF
    C:ADD 102
    MOV ACC LEFT
    @3
    MOV ANY DOWN
    MOV ANY UP
    @4
    MOV UP DOWN
    MOV ANY UP
    MOV UP DOWN
    MOV ANY UP
    MOV UP DOWN
    MOV ANY UP
    MOV UP DOWN
    MOV ANY UP
    MOV UP RIGHT
    MOV ANY DOWN
    MOV ANY UP
    @5
    MOV ANY DOWN
    MOV ANY LEFT
    @6
    ADD UP
    MOV 70 DOWN
    MOV 105 DOWN
    MOV 122 DOWN
    MOV 122 DOWN
    MOV 0 UP
    @7
    MOV UP ACC
    JEZ N
    MOV ACC DOWN
    N:MOV -1 RIGHT
    MOV 0 UP
    @8
    MOV ANY ACC
    JLZ N
    MOV 66 DOWN
    MOV 117 DOWN
    MOV 122 DOWN
    MOV 122 DOWN
    MOV 0 UP
    JRO -7
    N:MOV 10 DOWN
    

    Layout (48 bytes):

    3 3
    CCCCCCCCC
    O0 ASCII -
    O1 NUMERIC -
    O2 ASCII -
    

    Try it online!

    Explanation

    I think my TIS emulator is ready for its debut! This is an emulator inspired by (and based on) the wonderful game TIS-100. However, where the game only emulates the 100 model of the TIS series, I have designed this emulator to reflect the full range of possibilities.

    The code is in the format standardized by the game; we'll get to that in a bit. But first, the layout description just below that.

    Layout

    This is a specification for which model and configuration within the TIS range we desire. Whereas the model in the game (also called TIS-100) is only found in a 3 rows by 4 columns layout, for this solution I require something different.

    I desire a 3 by 3 square instead. Since there are multiple types of nodes that can fall in each slot, I specify that all nine are Compute nodes (other types include e.g. stack memory).

    In a TIS, the top row of nodes may read in input from above themselves (if so configured) and the bottom row may write below themselves to perform output (again, if so configured). For this challenge, no Inputs are needed, but I desire three different Outputs, corresponding to the three columns in this layout.

    The first and third column outputs (O0 and O2) are each in ASCII mode; this means that they will translate the internal numeric type to an ASCII character when performing output. The center column (O1) is a NUMERIC output, meaning that the values sent to this output will instead be written out as a number. In all cases, we want the data to go to stdout (-).

    Putting all this together gives the layout file seen above.

    Code

    TIS assembly code is stored in a flat file, as seen above. The code under the heading @0 will go in the first compute node, @1 in the second compute node, and so on. The layout in this solution looks like this:

    0 1 2
    3 4 5
    6 7 8
    

    Since each compute node only has capacity for 15 lines of code, my solution distributes the primary logic across 6 different nodes (the other three just bus data back and forth). Those 6 nodes are as follows:

    Node @2, the top right, is the counter, counting 1 through 100, and terminating execution (HCF) upon reaching 101.

    Node @1, the top center, sends every third number left (for Fizz), and all numbers down.

    Node @6, the bottom left, produces "Fuzz" when given any number.

    Node @4, the true center, sends every fifth number right (for Buzz), and all numbers down.

    Node @8, the bottom right, produces "Buzz" when given a non-negative number and "\n" otherwise.

    Node @7, the bottom center, produces a number if that number hasn't already been Fizzed or Buzzed (or both), and then requests a newline to be printed.

    It is quite possible that this is not yet a fully optimal golf, but this is also the first golf I've done for TIS.

    Phlarx

    Posted 2015-09-24T19:23:54.480

    Reputation: 1 366

    Hmm, I'm thinking that due to the decisions here, especially point 2, I could argue for not including the layout in the byte count. It is a 'different implementation', essentially. Opinions appreciated.

    – Phlarx – 2018-03-29T21:31:41.687

    1

    Jstx, 36 bytes

    ₧&0←+☺:@♥>ø↕₧K2→+◙♣>ø↕₧O2→+◙%↓2◙∟416
    

    Explanation

    ₧& # Push literal 100
    0  # Enter an iteration block over the first stack value and push the iteration element register at the beginning of each loop.
    ←  # Push literal false
    +  # Store the first stack value in the a register.
    ☺  # Push literal 1
    :  # Push the sum of the second and first stack values.
    @  # Push three copies of the first stack value.
    ♥  # Push literal 3
    >  # Push the modulus of the second and first stack values.
    ø  # Push literal 0
    ↕  # Enter a conditional block if the top two stack values are equal.
    ₧K # Push literal Fizz
    2  # Print the first stack value.
    →  # Push literal true
    +  # Store the first stack value in the a register.
    ◙  # End a conditional block.
    ♣  # Push literal 5
    >  # Push the modulus of the second and first stack values.
    ø  # Push literal 0
    ↕  # Enter a conditional block if the top two stack values are equal.
    ₧O # Push literal Buzz
    2  # Print the first stack value.
    →  # Push literal true
    +  # Store the first stack value in the a register.
    ◙  # End a conditional block.
    %  # Push the value contained in the a register.
    ↓  # Enter a conditional block if first stack value exactly equals false.
    2  # Print the first stack value.
    ◙  # End a conditional block.
    ∟  # Push literal null
    4  # Print the first stack value, then a newline.
    1  # End an iteration block.
    6  # Ends program execution.
    

    Try it online!

    Quantum64

    Posted 2015-09-24T19:23:54.480

    Reputation: 371

    1

    Phooey, 57 bytes

    &1[101>&0<@@%3{"Fizz">&1<}&%5{"Buzz">&1<}&>{<$i>}$c10<+1]
    

    Try it online!

    Explanation

    &1                    set current cell to 1
    [101                  until that cell is 101:
      >&0<                zero the cell to the right
      @@                  push two copies of the current cell to the stack
      %3{"Fizz">&1<}      if it's divisible by 3, print "Fizz"
      &%5{"Buzz">&1<}     if it's divisible by 5, print "Buzz"
      &                   restore cell
      >{<$i>}             if it's not, print the restored cell
      $c10                print a newline
      <+1                 increment the current cell
    ]
    

    Conor O'Brien

    Posted 2015-09-24T19:23:54.480

    Reputation: 36 228

    This actually doesn't look like such a bad language – ASCII-only – 2018-04-20T13:02:42.060

    @ASCII-only Thank you! – Conor O'Brien – 2018-04-20T13:05:25.590

    There's only one problem: this is nothing like Foo :P – ASCII-only – 2018-04-20T13:16:46.563

    @ASCII-only This is strikingly like foo, actually. The only thing in this answer unlike foo are the new while loops [...] – Conor O'Brien – 2018-04-20T13:18:13.423

    ockquote>

    _> actually... have I spent my entire life thinking the meme language Foo/how it's represented in the meme post was actually all Foo did

    – ASCII-only – 2018-04-20T13:33:55.833

    @ASCII-only So did I, which is one reason I made this language: to emphasize just how cool Foo was. – Conor O'Brien – 2018-04-20T13:38:35.820

    1

    ORACLE SQL (107 bytes)

    select nvl(decode(mod(rownum,3),0,'Fizz')||decode(mod(rownum,5),0,'Buzz'),rownum)from xmltable('1 to 100')
    

    DEMO

    Kamil Mętrak

    Posted 2015-09-24T19:23:54.480

    Reputation: 11

    1

    Pyret, 150 bytes

    d={(a,b):if num-modulo(a,b) == 0:if b == 3:"Fizz"else:"Buzz" end else:""end}
    each({(y):q=d(y,3) + d(y,5)
    print(if q == "":y else:q end)},range(1,101))
    

    You can try this online by copying it into the online Pyret editor!

    Pyret is a language designed with education in mind, so there's a couple things it enforces to keep things readable in normal programs. This explains why some of the operators are surrounded by spaces and the presence of newlines in the program.

    The {(...): ...} syntax is shorthand for lambda expressions, which gives us the following ungolfed version:

    d = lam(a,b):
      if num-modulo(a,b) == 0:
        if b == 3:
          "Fizz"
        else:
          "Buzz" 
        end 
      else:
        ""
      end
    end
    
    each(
      lam(y):
        q = d(y,3) + d(y,5)
        print(
          if q == "":
            y 
          else:
            q 
          end)
      end,
      range(1,101))
    

    Tango

    Posted 2015-09-24T19:23:54.480

    Reputation: 121

    1

    Python 2.7, 105 bytes

    for i in range(1,101):
     w=''
     if i%3==0:w+='Fizz'
     if i%5==0:w+='Buzz'
     if w!='':print w
     else:print i
    

    I know this can be golfed a lot. But I don't know how though.

    StealthyPanda

    Posted 2015-09-24T19:23:54.480

    Reputation: 41

    1General golf tip that is surprisingly pythonic: w!='' can be w. – Jonathan Frech – 2018-07-18T11:07:32.957

    Though for a more golfed version of the straight-forward approach, see this answer.

    – Jonathan Frech – 2018-07-18T11:12:30.410

    1

    Lua, 80 bytes

    Can probably be improved:

    s=("").sub for i=1,100 do r=s("Fizz",i%3*5)..s("Buzz",i%5*5)print(r..s(i,#r))end
    

    Readable version:

    s=("").sub
    for i=1,100 do
      r=s("Fizz",i%3*5)..s("Buzz",i%5*5)
      print(r..s(i,#r))
    end
    

    GalladeGuy

    Posted 2015-09-24T19:23:54.480

    Reputation: 101

    1

    Groovy, 63 bytes

    Stand-alone program, prints result to STDOUT.

    100.times{n->s=(++n%3?'':'Fizz')+(n%5?'':'Buzz')
    println s?s:n}
    

    I'd have preferred to use (1..100).each{ instead of 100.times{, so that I didn't have to ++n at the start of each iteration, but this is golf and that saves me two bytes.

    Other than that, a pretty standard truthy-based submission. 'Fizz' and 'Buzz' are added when remainder is 0 because 0 is falsy, and '' is a falsy string, so I can print n when the first line hasn't had either of 'Fizz' or 'Buzz' added.

    Try it online!

    archangel.mjj

    Posted 2015-09-24T19:23:54.480

    Reputation: 81

    1

    Python 3, 62 bytes

    for _ in range(1,101):print("Fizz"*(_%3<1)+"Buzz"*(_%5<1)or _)

    Try it online!

    Josh B.

    Posted 2015-09-24T19:23:54.480

    Reputation: 105

    1

    K (oK), 49 46 43 bytes

    Solution:

    `0:{$[a:,/$&`Fizz`Buzz!~5 3!'x;a;x]}'1+!100
    

    Try it online!

    Explanation:

    `0:{$[a:,/$&`Fizz`Buzz!~5 3!'x;a;x]}'1+!100 / the solution
                                           !100 / range 0..99
                                         1+     / add 1
       {                               }'       / apply lambda {} to each number
        $[                        ; ; ]         / conditional, $[if;then;else] 
                            5 3!'x              / apply modulo (!) of each 5 and 3 to the input x
                           ~                    / not (0->1, anything else->0)
                `Fizz`Buzz!                     / turn results into a dictionary
               &                                / keys where true
              $                                 / convert to strings
            ,/                                  / flatten
          a:                                    / save as a
                                   a            / result if a is not empty - so Fizz / Buzz
                                     x          / result if a is empty - so 1, 2, 4
    `0:                                         / print to stdout
    

    Notes:

    • -6 bytes thanks to @ngn with a new approach

    streetster

    Posted 2015-09-24T19:23:54.480

    Reputation: 3 635

    12 2/ -> 2/­­­­, @' -> ' – ngn – 2018-10-01T03:48:41.220

    it produces the same output without the $ – ngn – 2018-10-02T13:13:30.527

    \Fizz`Buzz`FizzBuzz->a,,,/$a:`Fizz`Buzz` – ngn – 2018-10-02T13:18:52.330

    1and here's a slightly shorter one abusing "where" on dicts: \0:{$[a:,/$&`Fizz`Buzz!~5 3!'x;a;x]}'1+!100` – ngn – 2018-10-02T13:37:46.887

    1

    Alchemist, 101 bytes

    0x+f+b->Out__+x+b
    0x+0f->Out_"Fizz"+2f+x
    0x+0b+f->Out_"Buzz"+5b+x
    x+0b->f
    x+b+a->_+Out_"\n"!99a+2f+4b
    

    Try it online!

    Takes a few confusing shortcuts in order to reuse the Buzz for FizzBuzzs.

    Explanation:

    !99a+2f+4b           # Initialise the program with 
                             # 99a (overall counter)
                             # 2f (Fizz counter)
                             # 4b (Buzz counter)
                             # 1_ (num counter)
    
    0x+f+b->Out__+x+b        # If there's a Fizz and Buzz counter, print the current number
                             # Also decrement the Fizz counter
    0x+0f->Out_"Fizz"+2f+x   # If there's no Fizz counter, print Fizz
                             # And reset the Fizz counter
    0x+0b+f->Out_"Buzz"+5b+x # If there's no Buzz counter and there is a Fizz counter, print Buzz
                             # Reset the Buzz counter
                             # And decrement the Fizz counter
    
    # After we've printed any of these, set the x flag
    x+0b->f                  # If there is also no Buzz counter, go back to the Buzz printer
                             # This is to ensure the Buzz check comes after the Fizz check
    x+b+a->_+Out_"\n"        # Otherwise, decrement the total counter
                             # Decrement the Buzz counter
                             # Increment the num counter
                             # And print a newline
    

    Jo King

    Posted 2015-09-24T19:23:54.480

    Reputation: 38 234

    1

    Ink, 77 70 57 48 bytes

    -(n){n%3:{n%5:{n}}|Fizz}{n%5: |Buzz}
    {n<100:->n}
    

    Try it online!

    Sara J

    Posted 2015-09-24T19:23:54.480

    Reputation: 2 576

    1

    Brachylog, 48 bytes

    100⟦₁{f{∋15∧"FizzBuzz"|∋3∧"Fizz"|∋5∧"Buzz"|t}ẉ}ᵐ
    

    Try it online!

    Probably not golfed too well but it works.

    Unrelated String

    Posted 2015-09-24T19:23:54.480

    Reputation: 5 300

    1

    C++ 123 122 bytes -1 thanks to JonathanFrech

    #import<iostream>
    #define s std::cout<<
    main(){for(int i;100-i++;s(i%3?"":"Fizz")<<(i%5?"":"Buzz")<<'\n')i%3*i%5?s i:s"";}
    

    Yoris

    Posted 2015-09-24T19:23:54.480

    Reputation: 31

    You can move the declaration of i inside the loop. Furthermore, is this variables initial value guaranteed to be zero? – Jonathan Frech – 2019-03-22T14:36:03.780

    @JonathanFrech I read somewhere that global ints are automatically initialized to 0 – Yoris – 2019-03-22T20:53:09.197

    1

    C, 98 94 bytes

    i;main(){for(;++i<101;)i%3*i%5?printf("%d\n",i):printf("%s%s\n",i%3?"":"Fizz",i%5?"":"Buzz");}
    

    Pretty simple stuff...

    Thanks to Yoris Fresh for helping me save a couple bytes. Thanks to Jerry Jeremiah for pointing out a mistake in the ungolfed version.

    Ungolfed:

    i;
    main() {
        for (; ++i < 101;)
            i % 3 && i % 5 ?
                printf("%d\n",i) :
                printf("%s%s\n", i % 3 ? "" : "Fizz", i % 5 ? "" : "Buzz");
    }
    

    qookie

    Posted 2015-09-24T19:23:54.480

    Reputation: 81

    the ungolfed version increments i twice each loop. – Jerry Jeremiah – 2019-06-04T03:33:26.360

    1

    05AB1E, 24 bytes

    тÝ3Å€"Fizz"}5Å€á”ÒÖ”J}¦»
    

    Try it online!

    Explanation:

    тÝ                  # range 0..100
      3Å€      }        # for every 3rd element...
         "Fizz"         # replace it with Fizz    
      5Å€      }        # for every 5th element...
         á              # keep only letters...
          ”ÒÖ”J         # and append "Buzz"
                ¦       # drop the first element
                 »      # join with newlines
                        # implicit output
    

    Or alternatively:

    тÝ35vyÅ€á”FizzÒÖ”#NèJ]¦»
    

    Try it online!

    35vy iterates over the digits of 35, which avoids repeating Å€}. ”FizzÒÖ” is the string Fizz Buzz, and then #Nè selects the appropriate element.

    Legacy 05AB1E doesn’t have Å€, so neither of those work for it. However, legacy à (set intersection) implicitly splits numbers, which lets us get a 26 that only works on legacy:

    тLεDÑ35Ãvá”Fizz ÒÖ”#yèJ},
    

    Try it online!

    тLε                         # for y in 1..100
       DÑ                       # divisors of y
         35Ã                    # keep only those in [3, 5]
            v               }   # for each...
             á                  # keep only letters
              ”Fizz ÒÖ”#yèJ     # append either Fizz or Buzz
                             ,  # print with newline
    

    Grimmy

    Posted 2015-09-24T19:23:54.480

    Reputation: 12 521

    1

    Julia, 87 Bytes

    for i in 1:100;println(i%3<1 ? "Fizz"*(i%5<1 ? "Buzz" : "") : (i%5<1 ? "Buzz" : i));end
    

    More readable:

    for i in 1:100
        if i%3 < 1
            print("Fizz")
            if i%5 < 1
                println("Buzz")
            else
                println()
            end
        elseif i%5 < 1
            println("Buzz")
        else
            println(i)
        end
    end
    

    Not sure if there's already a Julia submission here. Also my first time golfing c:

    Indirect thanks to @Najkin because I saw their reply to a C# submission saying that you can use <1 instead of ==0 and that helped me save 3 bytes over my previous 90-byte solution!

    BTW if you see any "unnecessary" spaces, they're actually necessary as Julia would throw a syntax error without them. (Why?!)

    Sagittarius

    Posted 2015-09-24T19:23:54.480

    Reputation: 169

    oh I just realized there's a 72-byte Julia submission lol – Sagittarius – 2019-08-28T14:02:11.023

    1

    Hoon, 115 bytes

    This is a Hoon say generator which can be used to write the output to a file from the dojo.

    turn is Hoon's map, it takes a list from 1..100 generated via (gulf 1 100) and uses string interpolation and the 'null check' conditional rune ?~ to generate either "Fizz", "Buzz" or "FizzBuzz" according to the value of x. This is paired with the value of x as a string <x> and then - and + are used to select the fizzbuzz string if not empty, otherwise the number string from the pair.

    :-
    %say
    |=
    *
    :-
    %txt
    %+
    turn
    (gulf 1 100)
    |=
    x=@
    =>
    "{?~((mod x 3) "Fizz" ~)}{?~((mod x 5) "Buzz" ~)}"^<x>
    ?~
    -
    +
    -
    

    mattnewport

    Posted 2015-09-24T19:23:54.480

    Reputation: 1 579

    1

    Wren, 78 bytes

    It turns out that this is pretty hard to golf.

    for(i in 1..100)System.print(i%15==0?"FizzBuzz":i%5==0?"Buzz":i%3==0?"Fizz":i)
    

    Try it online!

    user85052

    Posted 2015-09-24T19:23:54.480

    Reputation:

    1

    Keg, 58 40+4 43 bytes

    1(d|0&:3%[|`Fizz`,⑹]:5%[|`Buzz`,⑹]&[|:.]
    ,⑨
    

    Try it online!

    -14 bytes thanks to @EdgyNerd and then -1 byte due to using register

    Answer History

    58 bytes

    1(d|:\“%0=[`FizzBuzz`|:5%0=[`Buzz`|:3%0=[`Fizz`|:⅍]]],
    ,⑨)
    

    Try it online!

    String compression and string formatting are both useless here. Just a standard implementation of Fizzbuzz in Keg.

    Lyxal

    Posted 2015-09-24T19:23:54.480

    Reputation: 5 253

    1Idea to golf some bytes: couldn't you push an empty string, and then concatenate 'Fizz' if it's a multiple of 3, and then concat 'Buzz' if it's a multiple of 5, to save the FizzBuzz in your code (and probably some other bytes) – EdgyNerd – 2019-12-01T11:08:57.403

    1

    W d, 29 23 bytes

    &ó╞╟↨5O╓46N☻»½_49ƒZÄ▬«Σ
    

    A raw source is here.

    After decompression:

    2^                         E % Foreach in the 1..100 range
            a3m!                 % If the current item is divisible by 3:
      "Fizz"    *                % Return "Fizz"
                 "Buzz"a5m!*     % If the current item | 3 -> "Buzz".
                            +    % Join those results
                             a|  % Logical OR this result with the current item
                                  % Implicit print
    

    user85052

    Posted 2015-09-24T19:23:54.480

    Reputation:

    1

    DIVSPL, 22 bytes

    1..100
    fizz=3
    buzz=5
    

    Ethan McCue

    Posted 2015-09-24T19:23:54.480

    Reputation: 131

    1

    Rust, 114 bytes

    It's not the shortest one available (on code-golf.io someone managed to somehow solve it in 99 bytes, but I have no idea how).

    fn main(){(1..101).for_each(|i|println!("{}",["FizzBuzz","Fizz","Buzz",&i.to_string()][1.min(i%5)+2.min(i%3*2)]))}
    

    First off, the obvious part

    fn main() {/*..*/}
    

    Then we iterate from 1 to 100 (inclusive) and println! an element of the array

    (1..101).for_each(|i| println!("{}", ["FizzBuzz", "Fizz", "Buzz", &i.to_string()][/*..*/]))
    

    To choose the right index, we use the following, where i is the current number

    1.min(i % 5) + 2.min((i % 3) * 2)
    

    The first part is 0 if i is a multiple of 5. Otherwise it's 1.

    The second part is 0 if i is a multiple of 3. Otherwise it's 2.

    Examples:

    1.min(1 % 5) + 2.min((1 % 3) * 2) == 1 + 2 == 3 => "1"
    1.min(3 % 5) + 2.min((3 % 3) * 2) == 1 + 0 == 1 => "Fizz"
    1.min(4 % 5) + 2.min((4 % 3) * 2) == 1 + 2 == 3 => "4"
    1.min(5 % 5) + 2.min((5 % 3) * 2) == 0 + 2 == 2 => "Buzz"
    1.min(15 % 5) + 2.min((15 % 3) * 2) == 0 + 0 == 0 => "FizzBuzz"
    

    This way, if both parts produce 0, we get the string FizzBuzz. If the sum is 1 we get Fizz, if it's 2 Buzz, if it's 3 we get &i.to_string() (the stringified number).

    Axel Montini

    Posted 2015-09-24T19:23:54.480

    Reputation: 111

    1

    Frink, 131 bytes

    This is still to be golfed, but because the docs are bare bones, it will be golfed through experimentation

    for x=1 to 100
    {
    if x%15==0
    {
    println["FizzBuzz"]
    } else
    {
    if x%3==0
    {
    println["Fizz"]
    } else
    {
    if x%5==0
    {
    println["Buzz"]
    } else 
    {
    println[x]
    }
    }
    }
    }
    

    Beta Decay

    Posted 2015-09-24T19:23:54.480

    Reputation: 21 478

    By my reading of the linked page only the for loop's braces are necessary. – Neil – 2015-09-29T14:56:49.843

    @Neil Then you'd need then which would increase the byte count – Beta Decay – 2015-09-29T16:01:46.453

    No, that's only if you want the controlled statement on the same line. – Neil – 2015-09-29T16:13:30.333

    I might have misread so you might still need the braces on the outer else clauses too. – Neil – 2015-09-29T16:36:06.743

    1

    MATLAB, 172 bytes

    s=char(arrayfun(@(n){num2str(n)},[1:100 1e7])');s(3:3:end,1:4)=repmat('Fizz',33,1);s(5:5:100,1:4)=repmat('Buzz',20,1);s(15:15:100,:)=repmat('FizzBuzz',6,1);disp(s(1:100,:))
    

    Luis Mendo

    Posted 2015-09-24T19:23:54.480

    Reputation: 87 464

    1@TaylorScott Thanks for the edit – Luis Mendo – 2017-08-20T18:31:49.923

    1

    Hassium, 160 Bytes

    Here's it in Hassium. Surprised there's never been a FizzBuzz challenge before. There's also some lengthier (but more interesting) FizzBuzz examples here

    func main(){foreach(x in range(1,100)){if(x%15==0){println("fizzbuzz");}else if(x%3==0){println("fizz");}else if(x%5==0){println("buzz");}else println(x);}}
    

    Run online and see expanded version here

    Jacob Misirian

    Posted 2015-09-24T19:23:54.480

    Reputation: 737

    @FryAmTheEggman Duly noted and added. Thanks. – Jacob Misirian – 2015-09-25T02:19:27.390

    2>

  • The capitalization of Fizz and Buzz is wrong. 2. <1 is shorter than ==0. 3. All curly braces ({}) can be eliminated.
  • < – Dennis – 2015-09-25T05:29:26.817

    1

    JavaScript, 73 71 65 bytes

    for(i=1;i<101;i++)console.log((i%3?"":"Fizz")+(i%5?"":"Buzz")||i)
    

    Diego Torres

    Posted 2015-09-24T19:23:54.480

    Reputation: 161

    This was my first answer, what was the problem with the format? – Diego Torres – 2015-09-25T13:57:41.603

    Generally, language and size headers should be a header. Also, your current code doesn't seem to work, but you can fix it by replacing console.info with writeln (I tested it here and it worked.)

    – ASCIIThenANSI – 2015-09-25T13:59:13.563

    Do I need to specify the size or only the language? writeln is not valid in JavaScript, console.info is like console.log; both are valid. – Diego Torres – 2015-09-25T14:08:16.147

    Ah, OK, didn't realize that about writeln. You have to specify both the language and the size, on the same line. Also, I would reccommend using console.log if possible, that'll save you an extra byte. – ASCIIThenANSI – 2015-09-25T14:13:20.060

    Also, welcome to PPCG! – AdmBorkBork – 2015-09-25T14:13:56.660

    Thanks, Do you have a tool for calculating the size? – Diego Torres – 2015-09-25T14:17:15.083

    We usually use this.

    – LegionMammal978 – 2015-09-25T14:36:46.383

    1

    Groovy, 71 bytes

    (1..100).each{i->println i%15<1?'FizzBuzz':i%5<1?'Buzz':i%3<1?'Fizz':i}
    

    Kleyguerth

    Posted 2015-09-24T19:23:54.480

    Reputation: 61

    1

    Swift, 77 bytes

    for i in 1...100{print(i%15<1 ?"FizzBuzz":i%3<1 ?"Fizz":i%5<1 ?"Buzz":"\(i)")}
    

    Najkin

    Posted 2015-09-24T19:23:54.480

    Reputation: 171

    @RichardG.Nielsen It's considered poor etiquette to edit some else's golfed code. Suggesting it in a comment is fine, or you could post your own answer since you came up with it independently. – feersum – 2015-10-27T11:43:05.923

    1

    zsh, 65 63 bytes

    repeat 100 x=|let ++i%3||x=Fizz&&let i%5||x+=Buzz&&<<<${x:-$i}
    

    Changed echo to <<<. It's now 2 bytes shorter, because <<< doesn't need a space.

    repeat 100 x=|let ++i%3||x=Fizz&&let i%5||x+=Buzz&&echo ${x:-$i}
    

    iokanuon

    Posted 2015-09-24T19:23:54.480

    Reputation: 151

    1

    Python 2, 148 133 Bytes

    def f(n):
     if n%3+n%5<1:return"FizzBuzz"
     if n%5<1:return"Buzz"
     if n%3<1:return"Fizz"
     return n
    for x in map(f,range(1,101)):print x
    

    tommy_p1ckles

    Posted 2015-09-24T19:23:54.480

    Reputation: 11

    it is possible to save some bytes by reducing the amount of indentation. (1 space is sufficient) – Mhmd – 2015-09-27T18:12:32.593

    1@Mhmd it's probably actually tabs, SE converts them to 4 spaces. – undergroundmonorail – 2015-09-27T22:18:59.667

    if n%3+n%5==0:return"FizzBuzz" -> if n%3+n%5==0:return f(3)+f(5) EDIT: nevermind i miscounted, it's the same – undergroundmonorail – 2015-09-27T22:19:36.657

    1oh, but you can change ==0 to <1 everywhere it appears – undergroundmonorail – 2015-09-27T22:58:40.497

    1This can be shortened significantly by removing the function and return logic: for i in range(100):print(i%3+i%5<1and'FizzBuzz')or(i%5<1and'Buzz')or(i%3<1and'Fizz')or i golfs it down to 89 bytes. – Skyler – 2015-10-26T13:47:07.550

    1

    STATA, 115 bytes

    qui{
    set ob 100
    g a="Fizz" if!mod(_n,3)
    g b="Buzz" if!mod(_n,5)
    g c=a+b
    replace c=string(_n) if c==""
    }
    l c,noo noh
    

    qui{} suppresses output for everything in that block. First set the number of observations to be 100. Then generate variable a to be "Fizz" for every observation where its index number is divisible by 3. Then generate variable b to be "Buzz" for every observation where its index number is divisible by 5. Generate variable c to be the concatenation of these two. Then, replace c with the index number (STATA uses 1 indexing) if it is still an empty string. Then list the results of c in a table without observation numbers or headers.

    Only works in the "real" STATA interpreter. I need to add functions and conditions to the online interpreter for it to work there.

    A different solution in 116 bytes:

    forv x=1/100{
    if!mod(`x',3){
    di"Fizz"_c
    if!mod(`x',5) di"Buzz"_c
    }
    else if!mod(`x',5) di"Buzz"_c
    else di `x' _c
    di
    }
    

    This solution goes through a for loop and checks whether the loop variable is divisible by 3 or not. If it is, it prints "Fizz". Then it checks if it is divisible by 5 and prints "Buzz". Otherwise, it checks if it is divisible by 5 and prints "Buzz". If not, it prints the loop variable.

    bmarks

    Posted 2015-09-24T19:23:54.480

    Reputation: 2 114

    1

    rs, 92 91 bytes

    (_)^^(100)
    +^(_+)(_)/\1 \1\2
    \b((___)+)\b/Fi;\1
    \b(_{5})+\b/Bu;
    ;_*/zz
    \b(_+)\b/(^^\1)
     /\n
    

    Saved 1 byte thanks to @MartinBüttner!

    Live demo. (It may take a bit to run!)

    kirbyfan64sos

    Posted 2015-09-24T19:23:54.480

    Reputation: 8 730

    Do you not have \0 in rs? You can probably save some bytes either way by using the trick from my Retina answer: \b((___)+)\b/Fi;\1 ... \b(_{5})+\b/Bu; ... ;_+/zz – Martin Ender – 2015-09-28T14:38:12.380

    @MartinBüttner Thanks! I updated the post. What exactly do you mean by \0? – kirbyfan64sos – 2015-10-01T19:44:23.287

    Something to reference the entire match, not just a capturing group. – Martin Ender – 2015-10-01T19:59:47.247

    @MartinBüttner I guess not. :( – kirbyfan64sos – 2015-10-01T20:05:45.697

    @MartinBüttner I'm just using Python's built-in substitution thing. I can easily override it, though... – kirbyfan64sos – 2015-10-01T20:06:49.883

    1

    C# using LINQ, 168 186

    using System.Linq;class A{static void Main(){foreach(var s in Enumerable.Range(1,100).Select(n=>n%3==0?n%5==0?"FizzBuzz":"Fizz":n%5==0?"Buzz":n.ToString()))System.Console.WriteLine(s);}}
    

    Bill Tür

    Posted 2015-09-24T19:23:54.480

    Reputation: 111

    Don't you need to include using System.Linq; so that Enumerable can be referenced? – Ken Gregory – 2015-09-28T20:13:46.033

    @KenGregory You're right - thank's for pointing that out. I forgot that LINQPad (where I tried it) adds this implicitly. I've edited my anwer accordingly. – Bill Tür – 2015-09-28T20:31:19.093

    1

    UniBasic, 106 bytes

    FOR I=1 TO 100;D='';IF MOD(I,3)=0 THEN D='Fizz'
    IF MOD(I,5)=0 THEN D:='Buzz'
    IF D='' THEN D=I
    CRT D;NEXT I
    

    Ken Gregory

    Posted 2015-09-24T19:23:54.480

    Reputation: 151

    1

    C#, 155 142 Bytes

    class a{static void Main(){for(int i=0;i++<100;){var s="";if(i%3<1)s="Fizz";if(i%5<1)s+="Buzz";if(s=="")s=i+"";System.Console.WriteLine(s);}}}
    

    Added as an alternate approach to the example using LINQ

    Thanks @Riokmij!

    Ken Gregory

    Posted 2015-09-24T19:23:54.480

    Reputation: 151

    1You can replace the ==0's with <1, change the declaration of s with var instead of string, and replace the call to .ToString() by +"". Also, initial value for i should be 0. – Najkin – 2015-09-29T15:56:52.043

    1

    Windows Batch, 172

    @setlocal enableDelayedExpansion&for /l %%N in (1 1 100) do @(set v=&set/a1/(%%N%%3^)||set v=Fizz&set/a1/(%%N%%5^)||set v=!v!Buzz&if defined v (echo !v!)else echo %%N)2>nul
    

    dbenham

    Posted 2015-09-24T19:23:54.480

    Reputation: 131

    1

    MSX-BASIC, 106 bytes

    1FORI=1TO100:IFIMOD3=0ANDIMOD5=0THEN?"FizzBuzz"ELSEIFIMOD3=0THEN?"Fizz"ELSEIFIMOD5=0THEN?"Buzz"ELSE?I
    2NEXT
    

    The one-liner version to be executed in direct mode would be 120 bytes because all of the extra NEXTs needed before the ELSEs:

    FORI=1TO100:IFIMOD3=0ANDIMOD5=0THEN?"FizzBuzz":NEXTELSEIFIMOD3=0THEN?"Fizz":NEXTELSEIFIMOD5=0THEN?"Buzz":NEXTELSE?I:NEXT
    

    Konamiman

    Posted 2015-09-24T19:23:54.480

    Reputation: 291

    1IFIMOD3=0ANDIMOD5=0 -> IFIMOD15=0? I think MSX BASIC could be tokenized too, which would decrease your byte count. – lirtosiast – 2015-09-30T14:53:59.123

    1

    OCaml, 106

    for i=1to 100do
    let(!)n=i mod n<1and p=Printf.printf
    in!3&p"Fizz"=();!5&p"Buzz"=()or!3||p"%d"i=();p"
    "done
    

    Apparently this isn't a very good attempt as the shortest one on anarchy golf is only 97.

    feersum

    Posted 2015-09-24T19:23:54.480

    Reputation: 29 566

    1

    Scala, 90 bytes

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

    Ben

    Posted 2015-09-24T19:23:54.480

    Reputation: 360

    1

    Dart, 88

    main({i:0}){while(i<100)print(["FizzBuzz","Fizz","Buzz",++i][(i%3).sign*2+(i%5).sign]);}
    

    Dart is somewhat hampered in the golfing by not having conversion between bool and int, but the sign getter on integers helps a little.

    lrn

    Posted 2015-09-24T19:23:54.480

    Reputation: 521

    1

    Groovy, 83 80 bytes

    (1..100).each{def f=it%3,b=it%5;println!f&&!b?'FizzBuzz':!f?'Fizz':!b?'Buzz':it}
    

    K. Klassen

    Posted 2015-09-24T19:23:54.480

    Reputation: 121

    1

    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')
    

    James Murphy

    Posted 2015-09-24T19:23:54.480

    Reputation: 267

    1

    , 32 chars / 47 bytes

    ⩥Ṥⓜᵖ`FizzBuzz`ė⧺_%3⅋4,_%5?4:8)⋎_
    

    Try it here (Firefox only).

    Mama Fun Roll

    Posted 2015-09-24T19:23:54.480

    Reputation: 7 234

    1

    APL, 56 50 bytes

    ⊣{1+⍵⊣⎕←∊2↑((0=3 5|⍵)/'Fizz' 'Buzz'),''(⍕⍵)}⍣100⊢1
    

    Note: The very first should suppress output in GNU APL. Replace it with to get correct results in Dyalog, etc, or with portable assignment to some variable X← adding one byte.

    A+, 51 bytes

    (x←100)do↓⊃2↑((0=3 5|1+x)/4⊂'FizzBuzz'),⌽2↑<1↓⍕1+x;
    

    user46915

    Posted 2015-09-24T19:23:54.480

    Reputation: 201

    These seem quite different, so why not put them in different answers? – Martin Ender – 2015-11-09T07:47:41.107

    While I wouldn't call A+ a “trivial variant,” it's a direct derivative of APL and I think any solution in one would translate to similar byte count in another. Also, I just updated it making the answers work exactly the same way. – user46915 – 2015-11-09T09:22:57.543

    1

    ShapeScript, 57 bytes

    0'1+0?3%1<"Fizz"*1?5%1<"Buzz"*+"#0?"1?_1<*!@"
    "@'554***!#
    

    Try it online!

    How it works

    0          Push 0 (accumulator).
    '          Push a string that, when evaluated, does the following:
      1+         Increment the accumulator.
      0?         Push a copy.
      3%1<       Check if the remainder of its division by 3 is zero.
      "Fizz"*    Push "Fizz" for True, "" for False.
      1?         Push another copy of the accumulator.
      5%1<       Check if the remainder of its division by 5 is zero.
      "Buzz"*    Push "Buzz" for True, "" for False.
      +          Concatenate the potential fizzes and buzzes.
      "          Push a string that, when evaluated, does the following:
        #          Discard the topmost stack item.
        0?         Push a copy of the item below it (accumulator).
      "
      1?         Push a copy of the concatenation.
      _1<        Check if its length is zero.
      *!         Execute "#0?" once for True, zero times for False.
      @          Swap the generated output with the accumulator.
      "          Push "\n".
      "
      @          Swap it with the accumulator.
    '
    554**      Push 5 * 5 * 4 = 100.
    *!         Execute the '...' string 100 times.
    #          Discard the accumulator.
    

    Dennis

    Posted 2015-09-24T19:23:54.480

    Reputation: 196 637

    1

    scg, 51 bytes

    1á01°r{d[[d"Buzz"]["Fizz"d"Buzz"+]]\3%!@\5%!@"
    "}m
    

    So, does this mean that scg is a real language now? Explanation:

    1                         .- adds 1 to the stack
     á01                      .- adds 101 to the stack
        °r                    .- range, adds array with 1-100 on the stack
          {                   .- start function for use in map
           d                  .- duplicates number
           [                  .- array
            [
             d                .- duplicate number again, ends up in array
              "Buzz"          .- wonder what this does
                    ]         .- end array
            [
             "Fizz"
                   d          .- duplicate fizz
             "Buzz"+          .- ends up with "FizzBuzz"
                    ]
                     ]        .- end array. Ends up with a 2D array
            \                 .- gets number to calculate to the top
            3%                .- mod 3
              !               .- not, so any above 0 int turns to 0 and 0 turns to1
               @              .- get array value. Now you have two choices for output
                \5%!@         .- same as above but for 5.
                              .- now we have the correct fizzbuzz value
                     "\n"     .- pushes newline. I do not have variables yet so no shortcuts
                         }m   .- end function, map. output is implicit
    

    anOKsquirrel

    Posted 2015-09-24T19:23:54.480

    Reputation: 361

    1

    Rust, 145 137 131 bytes

    Golfed

    fn main(){for i in 1..101{let s=i.to_string();println!("{}",match i%15{0=>"FizzBuzz",3|6|9|12=>"Fizz",5|10=>"Buzz",_=>&(s)[..]});}}
    

    Ungolfed

    fn main() {
        for i in 1..101 {
            let s = i.to_string();
            println!("{}", match i % 15 {
                0        => "FizzBuzz",
                3|6|9|12 => "Fizz",
                5|10     => "Buzz",
                _        => &(s)[..]
            });
        }
    }
    

    Uses the current stable version of Rust (1.5.0).

    S22h

    Posted 2015-09-24T19:23:54.480

    Reputation: 151

    You can remove a semicolon after println! call, as println! returns (). Also, it's possible to replace &(s)[..] with &s. – Konrad Borowski – 2018-07-06T07:53:21.490

    1

    C#, 174 bytes

    void A(){for(int x=1;x<101;x++){if(x%15<1)Console.Write("FizzBuzz\n");else if(x%3<1)Console.Write("Fizz\n");else if(x%5<1)Console.Write("Buzz\n");else Console.WriteLine(x);}}
    

    Ungolfed:

    void A(){
        for (int x = 1; x < 101; x++) {
            if (x % 15 < 1) Console.Write("FizzBuzz\n");
            else if (x % 3 < 1) Console.Write("Fizz\n");
            else if (x % 5 < 1) Console.Write("Buzz\n");
            else Console.WriteLine(x);
        }
    }
    

    EnragedTanker

    Posted 2015-09-24T19:23:54.480

    Reputation: 309

    1

    Racket, 125 122 bytes

    (for([x(range 1 101)])(define(m n)(=(modulo x n)0))(displayln(cond[(and(m 3)(m 5))'FizzBuzz][(m 3)'Fizz][(m 5)'Buzz][x])))
    

    Simplest approach, took some work to get it lower than 130 bytes. Inspired by the Java example.

    Pretty-printed code

    (for ([x (range 1 101)])
      (define (m n)
        (= (modulo x n) 0))
      (displayln (cond
                   [(and (m 3) (m 5)) 'FizzBuzz]
                   [(m 3) 'Fizz]
                   [(m 5) 'Buzz]
                   [x])))
    

    Winny

    Posted 2015-09-24T19:23:54.480

    Reputation: 1 120

    1

    TCL, 208 bytes

    Golfed:

    set i 1;while {$i<101} {set p "";if {[expr $i % 3]==0} {set p [concat $p {fizz}]};if {[expr $i % 5]==0} {set p [concat $p {buzz}]};if {[expr $i % 3]>0&&[expr $i % 5]>0} {set p [concat $p $i]};puts $p;incr i;}
    

    Ungolfed:

    set i 1
    while {$i<101} {
        set p ""
        if {[expr $i % 3]==0} {set p [concat $p {fizz}]}
        if {[expr $i % 5]==0} {set p [concat $p {buzz}]}
        if {[expr $i % 3]>0 && [expr $i % 5]>0} {set p [concat $p $i]}
        puts $p
        incr i
    }
    

    Benjamin Williams

    Posted 2015-09-24T19:23:54.480

    Reputation: 109

    1

    Python 2, 91

    1;exec"print'FizzBuzz'if _%3==_%5==0else'Fizz'if _%3==0else'Buzz'if _%5==0else _;_+=1;"*100
    

    Oliver Ni

    Posted 2015-09-24T19:23:54.480

    Reputation: 9 650

    1

    Kotlin, 145 bytes

    fun main(a:Array<String>){IntRange(1,100).forEach{val f=it%3==0;val b=it%5==0;var x="";if(f)x+="Fizz";if(b)x+="Buzz";if(!f&&!b)x+=it;println(x)}}
    

    Try it online!

    Matt Sams

    Posted 2015-09-24T19:23:54.480

    Reputation: 131

    1

    Kotlin, 119 115 bytes

    fun main(a:Array<String>){for(i in 1..100)println(if(i%3<1)"Fizz" else ""+if(i%5<1)"Buzz" else if(i%3<1)"" else i)}
    

    Try it Online!

    The_Lone_Devil

    Posted 2015-09-24T19:23:54.480

    Reputation: 191

    Could you trim any more of the whitespace (e.g. in if(i % 5 < 1))? – ETHproductions – 2016-03-10T19:43:55.563

    :O I completely missed that there – The_Lone_Devil – 2016-03-10T19:46:09.750

    You need whitespace between a keyword and a literal, so I think that is all the whitespace that can be trimmed now – The_Lone_Devil – 2016-03-10T19:50:02.347

    Actually,it doesn't work for 15 and multiples: it only prints Fizz – Damiano – 2017-12-20T18:13:48.953

    Parenthesis around the first if/else can fix this in 117 bytes: fun main(a:Array<String>){for(i in 1..100)println((if(i%3<1)"Fizz" else "")+if(i%5<1)"Buzz" else if(i%3<1)"" else i)} – Damiano – 2017-12-20T18:28:12.193

    1

    Ruby, 72 bytes

    (1..100).each{|n|puts "#{n%3==0?'Fizz':''}#{n%5==0?'Buzz':n%3!=0?n:''}"}
    

    Explanation

    For each number from 1 to 100, print 'Fizz' if the number mod 3 is 0, then if the number mod 5 is 0, print 'Buzz' else if the number mod 3 is 0, print the number.

    user54187

    Posted 2015-09-24T19:23:54.480

    Reputation:

    Hello, and welcome to PPCG! Great first post! – NoOneIsHere – 2016-06-03T14:58:35.770

    1

    Groovy, 61 bytes

    100.times{a=++it%3?"":"fizz"
    a+=it%5?"":"buzz"
    println a?:it}
    

    kinbiko

    Posted 2015-09-24T19:23:54.480

    Reputation: 111

    0

    DUP, 76 bytes

    [$$3/%$[]['F,'i,'z,'z,]?\5/%$[]['B,'u,'z,'z,]?*[$.][]?10,]c:0[$100<][1+c;!]#

    Explanation of program flow, code blocks:

    DUP has two default truth values: -1 (true, all bits set) and 0 (false, no bits set). For conditional evaluations every nonzero value is accepted as true, comparisons themselves lead to either -1 or 0.

    DUP has two conditional expressions, if-then-else and a while loop:

    [execute if not false][execute if false]?. E.g. 1['t,]['f,]? prints t to STDOUT, because 1 is not false.

    [condition][execute while not false]#. E.g. 5[$0>][$.1-]# prints the numbers 5,4,3,2,1 to STDOUT. The condition block tests the top stack value if it’s greater than 0, the execute block prints the number and decrements it.

    The condition that’s checked is always the topmost stack element, which gets popped off the stack during the check.

    [
        $$3/%$                              {dup,dup,push 3, moddiv, pop, dup}
        []                                  {if condition true do nothing}
          ['F,'i,'z,'z,]?                   {if condition false print Fizz}
        \5/%$                               {swap, push 5, moddiv, pop, dup}
        []                                  {if condition true do nothing}
          ['B,'u,'z,'z,]?                   {if condition false print Buzz}
        *                                   {mul}
        [$.]                                {if condition true dup, print to STDOUT}
            []?                             {if condition false do nothing}
        10,                                 {push 10, print char to STDOUT (newline)}
    ]c:                                     {define function c}
    
    0                                       {push 0}
    
    [$100<]                                 {while dup < push 100 true}
           [1+c;!]#                         {do push 1, add, execute function c}
    

    Step by step:

    instruction             stack
    0                       0
    [
    $                       0,0
    100                     0,0,100
    <                       0,-1
    ]                       0
    [
    1                       0,1
    +                       1               increment counter
    c;                      1,0             0=start address of function c
    !                       execute c
    [
    $$3                     1,1,1,3
    /                       1,1,1,0         mod,div operator (n mod 3, n div 3)
    %                       1,1,1           /% → mod
    $                       1,1,1,1         result of n%3 used as flag for later check
    []                      1,1,1           condition true→do nothing
    ['F,'i,'z,'z,]?                         skipped
    \                       1,1,1           swap top and 2nd stack elements
    5                       1,1,1,5
    /                       1,1,1,0         mod,div operator
    %                       1,1,1           /% → mod
    $                       1,1,1,1         n%5 flag
    []                      1,1,1           condition true → do nothing
    ['B,'u,'z,'z,]?                         skipped
    *                       1,1             multiply %3 and %5 flags, result is only >0
                                            if neither %3 nor %5 are 0.
    [                       1               if condition (flag)>0
     $                      1,1             dup
      .]                    1               print number to STDOUT: '1'
    []?                                     skipped
    
    back to while loop
    
    [
    $                       1,1
    100                     1,1,100
    <                       1,-1
    ]                       1
    [
    1                       1,1
    +                       2               increment counter
    c;                      2,0             0=start address of function c
    !                       execute c
    
    ...
    

    A full description of all operators and program flow can be found at my GitHub repository, together wtih my Julia interpreter of DUP.

    An online Javascript implementation showing useful debug information can be found here.

    A rather terse introduction can be found on the esolangs.org DUP page.

    M L

    Posted 2015-09-24T19:23:54.480

    Reputation: 2 865

    0

    REXX, 94 bytes

    f.=
    b.=
    f.0='Fizz'
    b.0='Buzz'
    do i=1 to 100
      f=i//3
      b=i//5
      r=f.f||b.b
      if r<i then r=i
      say r
      end
    

    Alternative 94 byte solution:

    f='FizzBuzz'
    do i=1 to 100
      r=left(f,(i//3=0)*4)right(f,(i//5=0)*4)
      if r='' then r=i 
      say r
      end
    

    idrougge

    Posted 2015-09-24T19:23:54.480

    Reputation: 641

    Managed to get it down to 81. https://codegolf.stackexchange.com/questions/58615/1-2-fizz-4-buzz/120791#120791

    – theblitz – 2017-05-16T09:55:16.343

    0

    Java, 153 145 bytes

    enum f{;static{for(int i=1;i<101;i++)System.out.println(i%3>0&i%5>0?i:(i%3<1&i%5<1?"FizzBuzz":(i%3<1?"Fizz":(i%5<1?"Buzz":0))));System.exit(0);}}
    

    Not as long as I expected it to be, maybe because I ommited main function and used an enum. Quite overcomplicated print statement.

    Ungolfed version(Modified to be readable) with comments:

    enum f {;                                       // Required because it is an enum
        static {                                    // static block
            for (int i = 1; i < 101; i++) {         // loop from 1 to 100 inclusive
                boolean by3 = i % 3 == 0;
                boolean by5 = i % 5 == 0;
    
                if (!by3 && !by5)                   // Not divisible by 3 and 5
                    System.out.println(i);          // Just show the number
                else if (by3 && by5)                // Divisible by both
                    System.out.println("FizzBuzz"); // Show FizzBuzz
                else if (by3)                       // Divisible only by 3
                    System.out.println("Fizz");     // Show Fizz
                else                                // Divisible only by 5
                    System.out.println("Buzz");     // Show Buzz
            }
            System.exit(0);                         // Required because there can't be output to stderr and it would crash trying to run main function
        }
    }
    

    Ungolfed not modified:

    enum f {;
        static {
            for (int i = 1; i < 101; i++)
                System.out.println(i % 3 > 0 & i % 5 > 0 ? i : (i % 3 < 1 & i % 5 < 1 ? "FizzBuzz" : (i % 3 < 1 ? "Fizz" : (i % 5 < 1 ? "Buzz" : 0))));
            System.exit(0);
        }
    }
    

    EDIT: Saved 8 bytes by replacing ==0 with <1, !=0 with >0 and && with &

    cookie

    Posted 2015-09-24T19:23:54.480

    Reputation: 271

    0

    S.I.L.O.S, 141 bytes

    lbla
    a+1
    c=1-(a%3)*(a%5)
    if c b
    printIntNoLine a
    lblb
    c=(a%3)
    if c d
    print Fizz
    lbld
    c=(a%5)
    if c c
    print Buzz
    lblc
    printLine 
    b=100-a
    if b a
    

    Try it online!

    Unfortunately SILOS is incredibly verbose, and an interpreter bug cost me a few extra bytes, but I think SILOS is "superior" only to scratch in this challenge.

    Rohan Jhunjhunwala

    Posted 2015-09-24T19:23:54.480

    Reputation: 2 569

    0

    ///, 209 208 bytes

    /I/
    EFizz
    //H/FizzE//G/
    Fizz
    //E/Buzz
    /1
    2G4I7
    8GE11G13
    14
    H16
    17G19I22
    23GE26G28
    29
    H31
    32G34I37
    38GE41G43
    44
    H46
    47G49I52
    53GE56G58
    59
    H61
    62G64I67
    68GE71G73
    74
    H76
    77G79I82
    83GE86G88
    89
    H91
    92G94I97
    98GBuA
    

    Esolanging Fruit

    Posted 2015-09-24T19:23:54.480

    Reputation: 13 542

    is it just me or is some of this redundant? there isn't much point in shortening Buzz to BuC if the bytes saved by that in general are less than the bytes added – Destructible Lemon – 2017-05-15T04:34:35.063

    0

    Fourier, 81 bytes

    |`Fizz`|F|`Buzz`|B1~i100(i~X%15{0}{1~XFB}X%5{0}{1~XB}X%3{0}{1~XF}X{i}{Xo}10ai^~i)
    

    Try it on FourIDE

    Who knew such a simple task would yield such a mammoth of a program!

    Pseudocode of the program:

    Function F {
        Print "Fizz"
    }
    
    Function B {
        Print "Buzz"
    }
    
    i = 1
    While i != 100
        X = i
        If X % 15 == 0
            X = 1
            Function F
            Function B
        End if
        If X % 5 == 0
            X = 1
            Function B
        End If
        If X % 3 == 0
            X = 1
            Function F
        End If
        If X == i
            Print X
        End if
        Print "\n"
        i += 1
    End while
    

    Beta Decay

    Posted 2015-09-24T19:23:54.480

    Reputation: 21 478

    you say function a in the ungolfed, do you mean function F? – Destructible Lemon – 2017-05-15T23:39:43.520

    also I don't think you get to call it mammoth if it fits on screen in one line, and the challenge actually isn't that simple – Destructible Lemon – 2017-05-15T23:40:45.767

    0

    Micro, 72 bytes

    :i{i1+:i"":d
    i3/i3%=if("Fizz":d,)
    i5/i5%=if(d"Buzz"+:d,)
    d:\i100=if(,a)}
    

    raddish0

    Posted 2015-09-24T19:23:54.480

    Reputation: 91

    0

    Python 2, 106 bytes

    for n in range(1,101):
        a="Fizz"*int(n%3==0)+"Buzz"*int(n%5==0)
        if a=="": print n
        else: print a
    

    Try it online!

    Husnain Raza

    Posted 2015-09-24T19:23:54.480

    Reputation: 329

    0

    Recursiva, 46 bytes

    EmB100"%a15:%a5:%a3:a!'Fizz'!'Buzz'!'FizzBuzz'
    

    Try it online!

    Explanation:

    EmB100"%a15:%a5:%a3:a!'Fizz'!'Buzz'!'FizzBuzz'
    E                                              - Stringify and join with new-lines
     m                                             - map with
      B100                                         - Range [1,2..100]
          "                                        - mapping function start
           %a15:%a5:%a3:a!'Fizz'!'Buzz'!'FizzBuzz' - string as per divisibility
    
    %a15:%a5:%a3:a!'Fizz'!'Buzz'!'FizzBuzz' roughly translates to this if-else block:
    
    if(a%15):
        elif(a%5):
            elif(a%3):
                return a
            else:
                return 'Fizz'
        else:
            return 'Buzz'
    else:
         return 'FizzBuzz'  
    

    officialaimm

    Posted 2015-09-24T19:23:54.480

    Reputation: 2 739

    0

    Jq 1.5, 90 bytes

    def f:if.%15<1then"FizzBuzz"elif.%5<1then"Buzz"elif.%3<1then"Fizz"else. end;range(100)+1|f
    

    Try it online!

    jq170727

    Posted 2015-09-24T19:23:54.480

    Reputation: 411

    0

    Modula-2, 222 bytes

    MODULE F;IMPORT InOut;VAR i:INTEGER;BEGIN
    FOR i:=1 TO 100 DO
    CASE i*i*i*i MOD 15 OF
    0:InOut.WriteString("FizzBuzz")|1:InOut.WriteInt(i,0)|6:InOut.WriteString("Fizz")|10:InOut.WriteString("Buzz")END;InOut.WriteLn
    END END F.
    

    Tested with Amsterdam Compiler Kit. The program needs 4-byte INTEGER. If using 2-byte INTEGER, i*i*i*i overflows and the program fails with a case error.

    With indentation:

    MODULE F;
    IMPORT InOut;
    VAR i: INTEGER;
    BEGIN
      FOR i := 1 TO 100 DO
        CASE i * i * i * i MOD 15 OF
          0: InOut.WriteString("FizzBuzz")
        | 1: InOut.WriteInt(i, 0)
        | 6: InOut.WriteString("Fizz")
        | 10: InOut.WriteString("Buzz")
        END;
        InOut.WriteLn
      END
    END F.
    

    ACK compiles the PIM3 dialect of Modula-2 and comes with an InOut module. Other compilers for Modula-2 or Oberon might have shorter syntax or come with shorter modules.

    • I don't like having 3 calls to InOut.WriteString, but adding a PROCEDURE p(s:ARRAY OF CHAR);BEGIN InOut.WriteString(s)END p; would cost 61 bytes and save only 48 bytes in the calls.

    • I would write FOR i:=1TO 100DO but ACK rejects it as a syntax error.

    • I had used i*i*i*i MOD 15 in my AppleScript answer.

    kernigh

    Posted 2015-09-24T19:23:54.480

    Reputation: 2 615

    0

    Java (OpenJDK 8), 127 bytes

    interface J{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));}}
    

    Try it online!

    ungolfed:

    interface J {
        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));
        }
    }
    

    Luca H

    Posted 2015-09-24T19:23:54.480

    Reputation: 163

    0

    nodejs repl, 60 bytes

    for(i=0;++i<101;util.puts(i%5?s||i:s+'Buzz'))s=i%3?'':'Fizz'
    

    With latest node, this prints a deprecation warning to the console. This presumably violates the rule about printing to STDERR, but using an older version of node will fix this.

    Armand

    Posted 2015-09-24T19:23:54.480

    Reputation: 499

    0

    APL Nars 93 chars

    h;i;j
    i←0
    L:j←0⋄i+←1⋄→A×⍳0≠3∣i⋄⍞←'Fiz'⋄j←1
    A:→B×⍳0≠5∣i⋄⍞←'Buz'⋄j←1
    B:→C×⍳j=0⋄→D
    C:⍞←i
    D:⎕←''⋄→L×⍳i≤99
    

    Indented:

     ∇ h;i;j
      i←0
    L:j←0⋄i+←1⋄→A×⍳0≠3∣i⋄⍞←'Fiz'⋄j←1
    A:         →B×⍳0≠5∣i⋄⍞←'Buz'⋄j←1
    B:         →C×⍳j=0⋄→D
    C:    ⍞←i
    D:    ⎕←''⋄→L×⍳i≤99 ∇
    

    RosLuP

    Posted 2015-09-24T19:23:54.480

    Reputation: 3 036

    0

    Clean, 148 + 2 = 150 bytes

    +2 for the -b compiler flag

    module m
    import StdEnv
    f[0,0,_]="FizzBuzz"
    f[a,b,n]|a==0="Fizz"|b==0="Buzz"=fromInt n
    Start=flatlines[fromString(f[n rem 3,n rem 5,n])\\n<-[1..100]]
    

    Try it online!

    Οurous

    Posted 2015-09-24T19:23:54.480

    Reputation: 7 916

    0

    MY-BASIC, 116 bytes

    A response.

    For i=1 To 100
    S=""
    If i Mod 3=0 Then S="Fizz"
    If i Mod 5=0 Then S=S+"Buzz"
    If S="" Then Print i; Else Print S;
    Next
    

    Try it online!

    Taylor Scott

    Posted 2015-09-24T19:23:54.480

    Reputation: 6 709

    0

    Ada (GNAT), 196 bytes

    procedure GNAT.IO.F is begin for I in Integer range 1..100 loop Put((if I mod 3=0 then"Fizz"else"")&(if I mod 5=0 then"Buzz"else""));if I mod 3*I mod 5/=0 then Put(I);end if;New_Line;end loop;end;
    

    Try it online!

    189 bytes if extraneous whitespace is allowed:

    procedure GNAT.IO.F is begin for I in Integer range 1..100 loop Put(if I mod 3=0 then(if I mod 5=0 then"FizzBuzz"else"Fizz")else(if I mod 5=0 then"Buzz"else I'Image));New_Line;end loop;end;
    

    Try it online!

    ASCII-only

    Posted 2015-09-24T19:23:54.480

    Reputation: 4 687

    0

    C#, 119 bytes

    class q{static void Main(){for(var i=0;i++<100;)System.Console.WriteLine(i%3*i%5>0?i+"":$"{i%3:;;Fizz}{i%5:;;Buzz}");}}
    

    Try it online!


    I was wondering how close I could get to the long standing 124 byte C# answer by Pierre-Luc, so I challenged myself to try. After unexpectedly beating it by just one byte (123 bytes, Try it online!), I took the advice from @LiamK's three year old comment and used string interpolation to shave off another 4 bytes. I'm genuinely surprised by how well this worked out!

    Maz

    Posted 2015-09-24T19:23:54.480

    Reputation: 191

    0

    Pyth, 39 bytes

    VS100J+?q0%N3"Fizz"k?q0%N5"Buzz"k?qJkNJ
    

    Try it online!

    There's probably an easier and shorter way. Also is(polishNotation, annoying).

    This is roughly equivalent to:

    for x in range(1,100):
    a = "" + "Fizz" if x%3==0 else "" + "Buzz" if x%5==0 else ""
    print(a if a!="" else x)
    

    Tryer

    Posted 2015-09-24T19:23:54.480

    Reputation: 71

    0

    Dart, 80 bytes

    f({i=0}){for(;i++<100;)print((i%3>0?'':'Fizz')+(i%5>0?(i%3>0?'$i':''):'Buzz'));}
    
    f({i=0}){for(;i++<100;)print("${i%3>0?'':'Fizz'}${i%5>0?(i%3>0?i:''):'Buzz'}");}
    
    f({i=0}){for(;i++<100;)print(i%15<1?'FizzBuzz':i%5<1?'Buzz':i%3<1?'Fizz':'$i');}
    

    Try it online!

    Elcan

    Posted 2015-09-24T19:23:54.480

    Reputation: 913

    0

    JavaScript (Node.js), 71 bytes

    for(i=0;++i<101;)console.log((l=i%3<1?"Fizz":'')+(i%5<1?"Buzz":l?"":i))
    

    Try it online!

    Kamil Naja

    Posted 2015-09-24T19:23:54.480

    Reputation: 121

    0

    Java 8, 129 bytes

    interface I{static void main(String[]s){for(int i=0;++i<101;)System.out.println(i%15<1?"FizzBuzz":i%3<1?"Fizz":i%5<1?"Buzz":i);}}
    

    Try it online

    Benjamin Urquhart

    Posted 2015-09-24T19:23:54.480

    Reputation: 1 262

    0

    JavaScript, 127 122 81 79 bytes

    for(e=0;++e<101;)console.log(e%3||e%5?e%3==0?"Fizz":e%5==0?"Buzz":e:"FizzBuzz")
    

    Another way, based on Taylor Scott's solution, is only 78 72 bytes

    for(e=0;++e<101;)s=e%3?"":"Fizz",s+=e%5?"":"Buzz",console.log(""==s?e:s)
    

    Try it online! - First Solution

    Try it online! - Second Solution

    Ryan Knutson

    Posted 2015-09-24T19:23:54.480

    Reputation: 1

    Thanks @JoKing I'm still getting back into OOP from procedural (college class) – Ryan Knutson – 2019-03-08T01:11:52.230

    Thanks @taylor-scott – Ryan Knutson – 2019-03-08T01:58:21.437

    2Stuff in the format a==0?b:c can be a?c:b – Jo King – 2019-03-08T02:30:33.030

    0

    Scheme, 118 bytes

    (for-each(lambda(i)(printf"~a~a~%"(if(=(mod i 3)0)'Fizz"")(if(=(mod i 5)0)'Buzz(if(=(mod i 3)0)""i))))(cdr(iota 101)))
    

    Try it online!

    Ungolfed:

    (for-each
     (lambda (i)
       (printf
        "~a~a~%"
        (if (= (mod i 3) 0) 'Fizz "")
        (if (= (mod i 5) 0) 'Buzz 
            ;; else
            (if (= (mod i 3) 0) "" i))))
     (cdr (iota 101)))
    

    waf9000

    Posted 2015-09-24T19:23:54.480

    Reputation: 21

    0

    Racket, 107 Bytes

    (for{[x 100]}(define(f a b n)(if(=(modulo(+ 1 x)n)0)a b))(printf"~a~a\n"(f'Fizz""3)(f'Buzz(f""(+ 1 x)3)5)))
    

    Try it online!

    The inspiration for my answer comes from Luca H's post.

    All I did afterwards was factor out the repetitive calls to (if (modulo ...) ...). Sadly, there are two copies of (+ 1 x) left that I couldn't factor out using less characters, so they remain.

    Ungolfed (including removing f):

    (for {[x 100]}
      (printf "~a~a\n"
              (if (= (modulo (+ x 1) 3) 0) 'Fizz "")
              (if (= (modulo (+ x 1) 5) 0) 'Buzz
                  (if (= (modulo (+ x 1) 3) 0) "" (+ x 1)))))
    

    waf9000

    Posted 2015-09-24T19:23:54.480

    Reputation: 21

    0

    Pip, 43 41 bytes

    Fa1,101{i:0a%3?i:1O"FIZZ"a%5?i?PaPxP"BUZZ"}

    Lh{i:0o%3?i:1O"FIZZ"o%5?i?PoPxP"BUZZ"++o}
    

    Try it online!

    Kenneth Taylor

    Posted 2015-09-24T19:23:54.480

    Reputation: 183

    0

    33, 60 bytes

    1asz'Fizz'{tlot}t[3rznpn1cztsl5rz"Buzz"npn1tlaz''nqtl1aztsi]
    

    Explanation:

    1asz          (Initialise the counter with 1)
    'Fizz'{tlot}t (Create function 'Fizz' to print current number)
    [             (Start of loop)
    3rz           (Check if divisible by 3)
    np            (If so, print 'Fizz')
    n1czts        (Store result for later)
    l             (Load the counter back)
    5rz           (Check if divisible by 5)
    "Buzz"np      (If so, print 'Buzz')
    n1tlaz        (Check if divisible by neither by retrieving the value from earlier)
    ''nqt         (If neither 'Fizz' nor 'Buzz' was printed, print the number)
    l1azts        (Restore our counter and increment it)
    i]            (Print a newline and repeat from the start of the loop)
    

    TheOnlyMrCat

    Posted 2015-09-24T19:23:54.480

    Reputation: 1 079

    0

    Visual Basic Script, 123 bytes

    For i=1To 100
    S=""
    If i Mod 3=0Then
    S="Fizz"
    End If
    If i Mod 5=0Then
    S=S+"Buzz"
    End If
    If S=""Then
    S=i
    End If
    MsgBox S
    Next
    

    Sorry @Taylor Scott but I basically copied your MY-BASIC solution

    Sagittarius

    Posted 2015-09-24T19:23:54.480

    Reputation: 169

    0

    Minefriff, 241 bytes

    0,`
    >I1,+:a*a1,=?;`~             o,aC            <  
    >:f,%?`Ca*c2,:a*b7,7*e,a*c2,:f*7,a*7,oooooooo^
    >:5,%?`Ca*c2,:a*b7,6*b,oooo                  ^
    >:3,%?`Ca*c2,:f*7,a*7,oooo                   ^
    >:o                                          ^ 
    

    There isn't a TIO interpreter link for Minefriff, but you can run it online here.

    What it actually looks like:

    300 px version Bigger

    Lyxal

    Posted 2015-09-24T19:23:54.480

    Reputation: 5 253

    0

    Python 3, 80 bytes

    for x in range(1,101):print(("Fizz"if x%3==0else"")+("Buzz"if x%5==0else"")or x)
    

    PythoNista

    Posted 2015-09-24T19:23:54.480

    Reputation: 1

    0

    Scala, 65 64 Bytes

    1.to(100).map(n=>{print(s"\n$n"+(if(n%3==0)"fizz")+(if(n%5==0)"buzz"))})
    

    I've just started golfing so any tips are appreciated (yes I have read this)

    gregam3

    Posted 2015-09-24T19:23:54.480

    Reputation: 1

    Not exactly. You have to output n only for those which are neither “fizz” or “buzz”. – manatwork – 2019-12-11T18:36:00.443

    @manatwork Okay good to know will fix – gregam3 – 2019-12-11T18:54:33.107

    0

    MC6000 ASM (Shenzhen I/O), 133 Bytes

    add 1
    mov acc x3
    mov 51 x2
    mov acc x2
    mov 3 x2
    teq x2 0
    +mov 1 x1
    mov 51 x2
    mov acc x2
    mov 5 x2
    teq x2 0
    +mov 2 x1
    slp 1
    mov -999 x1
    

    Uses an MC4010 co-processor on x2, numeric display on x3, and a custom fizzbuzz display on x1.

    "Hardware":

    "Hardware" Configuration

    Custom LCD:

    enter image description here

    Technically doesn't follow the rules as MCxxxx don't have a STDOUT, but I did the best I could.

    nihilazo

    Posted 2015-09-24T19:23:54.480

    Reputation: 477

    0

    APL, 52 chars/bytes

    generate integers from 1 to n

    b is a 2 by n boolean matrix highlighting multiples of 3 and 5

    b←0=3 5∘.|⍵
    

    c is a boolean vector highlighting multiples of either 3 or 5

    c←∨⌿b
    

    format each integer into a character vector

    ⍕¨⍵
    

    where a number is a multiple of either 3 or 5...

    @{c}
    

    ...put either Fizz or Buzz (i.e. discard the last 4, the first 4 or no character at all from the string "FizzBuzz" according to b)

    (↓∘'FizzBuzz'¨¯4 4+.×c/b)
    

    transform the nested vector into a matrix

    Popov

    Posted 2015-09-24T19:23:54.480

    Reputation: 101

    0

    Stax, 27 bytes

    éeO├φ☻mRàzΦ╛`φ#2àáÿ²øΔ=L←§b
    

    Run and debug it

    Unpacked and Uncompressed

    A2#F~;3%z"Fizz"?;5%z"Buzz"?+cz=,a?P
    

    Nanajnaiojneg

    Posted 2015-09-24T19:23:54.480

    Reputation: 11

    Really clever golfs there! – a'_' – 2020-02-20T01:44:51.883

    0

    Symja, 140 bytes

    s="";For(i=1,i<101,i++,If(Mod(i,5)==0,s=s<>"Fizz");If(Mod(i,3)==0,s=s<>"Buzz");If(Mod(i,5)*Mod(i,3)!=0,s=s<>ToString(i));s=s<>"\n");Print(s)
    

    Y'all can try it online here. Note that you will need to copy and paste the above program into the box provided, and then press Shift+Return

    Just a standard fizzbuzz approach. This is tweetable BTW, so there's that too.

    Lyxal

    Posted 2015-09-24T19:23:54.480

    Reputation: 5 253

    0

    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)

    gilad hoch

    Posted 2015-09-24T19:23:54.480

    Reputation: 717

    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 – 2015-10-02T20:57:26.963

    0

    Python

    [[x,"fizz","buzz","fizzbuzz"][(x%3<1 and 1)+(x%5<1 and 2) or 0] for x in range(100)]
    

    Marco Pashkov

    Posted 2015-09-24T19:23:54.480

    Reputation: 117

    7Welcome to PPCG! I'm afraid this doesn't quite satisfy the spec of the challenge. This appears to be a (REPL?) snippet (not a full program), which evaluates to a list (instead of printing the results to STDOUT line by line) and doesn't use the right capitalisation (capital F and B) and also seems to have the range from 0 to 99 instead of 1 to 100. – Martin Ender – 2015-09-27T20:28:58.720

    Override header: Invalid - See what Martin said above ^ – Beta Decay – 2015-11-01T08:53:12.353

    You can use int(i%5<1) to save some bytes – maxb – 2018-09-14T17:00:00.710

    0

    Javascript ES6, 77 chars

    "\n".repeat(100).replace(/(?=\n)/g,(m,i)=>(++i%3?m:"Fizz")+(i%5?m:"Buzz")||i)
    

    Test:

    "\n".repeat(100).replace(/(?=\n)/g,(m,i)=>(++i%3?m:"Fizz")+(i%5?m:"Buzz")||i) == document.querySelector("pre").textContent
    

    Qwertiy

    Posted 2015-09-24T19:23:54.480

    Reputation: 2 697

    Here's my ES6 attempt, with parts stolen from yours (89 chars): "0".repeat(99).split(0).map((m,i)=>{return(++i%3?m:"Fizz")+(i%5?m:"Buzz")||i}).join("\n") – starbeamrainbowlabs – 2016-01-07T06:48:12.667

    @starbeamrainbowlabs, why do you use {return ...} instead of expression? – Qwertiy – 2016-01-07T10:21:27.753

    Because I couldn't get the expression to work :( – starbeamrainbowlabs – 2016-01-07T16:20:27.957

    Save a byte by using template strings + literal newline at front. – Mama Fun Roll – 2016-01-29T00:34:46.103

    0

    Python 91 Bytes

    for n in range(100):
        c=""
        if n%3==0:c+="fizz"
        if n%5==0:c+="buzz"
        if c=="":c=n
        print c
    

    JoshK

    Posted 2015-09-24T19:23:54.480

    Reputation: 139

    0

    Elixir, 182 bytes

    import Stream
    f=fn(n)->(zip(cycle(["","","fizz"]),cycle(["","","","","buzz"]))|>zip(iterate(1,&(&1 + 1)))|>map(fn{{"",""},n}->n
    {{p,o},_}->p<>o end))|>take(n)|>Enum.each(&IO.puts/1)end
    

    LiveDemo

    Calling: f.(100)

    lad2025

    Posted 2015-09-24T19:23:54.480

    Reputation: 379

    0

    ///, 229 bytes

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

    Leaky Nun

    Posted 2015-09-24T19:23:54.480

    Reputation: 45 011

    Out-golfed – Esolanging Fruit – 2017-05-15T02:58:06.367

    @Challenger5 Well done. – Leaky Nun – 2017-05-15T02:59:22.870

    @LeakyNum I have A CJam script that finds common substrings in the input. It's useful for /// golfing.

    – Esolanging Fruit – 2017-05-15T05:55:32.637

    0

    JavaScript (using external library) (90 bytes)

    x=>_.Range(1,100).Select(x=>x%3==0?(x%5==0?"FizzBuzz":"Fizz"):x%5==0?"Buzz":x).WriteLine()
    

    Link to library: https://github.com/mvegh1/Enumerable/

    Code explanation: Creates a range starting at 1 and extending 100 elements. Select maps the item according to the predicate. First check if divisible by 3, if so check if divisible by 5. If so, select "FizzBuzz", else select "Fizz". Otherwise,check if divisible by 5. If so, select "Buzz", else just select the number. WriteLine is built into the library, and it writes each element on its own line

    enter image description here

    applejacks01

    Posted 2015-09-24T19:23:54.480

    Reputation: 989