177
\$\begingroup\$

Introduction

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

Challenge

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

Output

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

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

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

Further Rules

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

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

  • Nothing can be printed to STDERR.

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

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

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

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

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

  • Standard loopholes are otherwise disallowed.

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

Catalogue

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

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

359 Answers 359

1
3 4
5
6 7
12
3
+200
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

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!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ To Taylor Scott: sorry for deleting the edit. I thought adding another language would be more meaningful \$\endgroup\$
    – Alex
    Apr 18 '18 at 23:25
  • 1
    \$\begingroup\$ Alex, while this is definitely a more interesting answer you should feel free to leave multiple responses to challenges. \$\endgroup\$ May 16 '18 at 14:18
3
\$\begingroup\$

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!

\$\endgroup\$
0
3
\$\begingroup\$

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

\$\endgroup\$
0
3
\$\begingroup\$

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
\$\endgroup\$
3
\$\begingroup\$

Javascript, 80 bytes

for(i=1;i<101;i++){console.log(i%3==0?i%5==0?"FizzBuzz":"Fizz":i%5==0?"Buzz":i)}
\$\endgroup\$
1
  • \$\begingroup\$ To whoever downvoted this; you really should explain why. Especially considering Jey is a new contributor. \$\endgroup\$
    – Marie
    Feb 27 '19 at 19:27
3
\$\begingroup\$

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  

\$\endgroup\$
2
  • \$\begingroup\$ Art⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ \$\endgroup\$ Mar 30 '21 at 15:42
  • \$\begingroup\$ @AndrewOgden Thank you! \$\endgroup\$
    – Adám
    Mar 30 '21 at 15:58
3
\$\begingroup\$

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
\$\endgroup\$
3
\$\begingroup\$

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`}
\$\endgroup\$
4
  • 1
    \$\begingroup\$ You don't need the last ; on the first line. A port to Bash takes 70 bytes, thus beating my answer. \$\endgroup\$
    – Dennis
    Aug 28 '19 at 14:49
  • 1
    \$\begingroup\$ Also, you don't need the newline before the last } (which is missing in your answer). Try it online! \$\endgroup\$
    – Dennis
    Aug 28 '19 at 14:56
  • \$\begingroup\$ the bash solution still wins for originality.. I couldn't port that crazy for expression to zsh \$\endgroup\$
    – roblogic
    Aug 28 '19 at 15:01
  • 1
    \$\begingroup\$ 61, mostly thanks to subshells \$\endgroup\$ Oct 15 '19 at 2:03
3
\$\begingroup\$

DIVSPL, 22 bytes

1..100
fizz=3
buzz=5
\$\endgroup\$
3
\$\begingroup\$

W n, 22 21 bytes

Seems like nobody ties with Dennis. Just 1 byte away...

♥:jΓƒ¢D╦Γ%%lOvhI♣BAE§

Uncompressed:

3m!?SY%?*?SZ%?a5m!*+a|2^N

Explanation

                      2^N For Each: 1 to 100
3m!                       Repeat whether current item is divisible by 3
   ?SY%?*                 Repeat that bool by the compressed "Fizz"
         ?SZ%?a5m!*       Do that for "Buzz" too
                   +      Join the results
                    a|    If the result is empty,
                          turn it to the current item value.

Flag: n                   Join the resulting list with newlines
                          Implicit output
```
\$\endgroup\$
3
\$\begingroup\$

Windows Batch, 149 bytes

@for /l %%N in (1 1 100)do @(set s=&set/a1/(%%N%%3^)||set s=Fizz&set/a1/(%%N%%5^)&&(if defined s (echo Fizz)else echo %%N)||call echo %%s%%Buzz)2>nul

The SET /A statements test the modulo 3 and 5 without using IF by intentionally dividing by zero and using && and || conditional command concatenation. Of course stderr must be disabled, but it still saves bytes vs an IF statement.

Windows Batch (unusual cmd.exe configuration, and environment assumption), 166 165 133 bytes

My original answer used delayed expansion, but the code to enable delayed expansion takes 32 bytes all on its own. However, some people have their cmd.exe configured to have delayed expansion enabled by default. For the small minority of people that configure cmd.exe this way, then the following is significantly shorter.

@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

Besides relying on an unusual cmd.exe configuration, it is also reliant on the absence of any environment variable names that begin with 1. This is normally safe because batch treats something like %1var% as batch parameter %1 followed by a string constant var - the trailing % would get stripped. So people are taught to never begin variable names with a digit.

\$\endgroup\$
3
\$\begingroup\$

><>, 59 bytes

0v!oo:oo"Fiz"\
1<oan?*/!?%5$\!?%3;?)*aa::::::+
o"Buzz"/$0oo

Try it online!

Prints a trailing newline

How it works

0v...
.<... Initialises the stack with 0
.....

.....
1<................;?)*aa::::::+ Increment the counter and duplicate it a looooot
.....                           End the program if the counter is larger than 100 (10*10)

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 an extra copy of the counter for each Fizz or Buzz (and two for FizzBuzzes). This is due to the extra copy(s) of the counter that don't end up being printed.

\$\endgroup\$
0
3
\$\begingroup\$

Spaghetti, 522 bytes

main:0"n"goto store goto l l:100"n"goto retrieve goto areEqual"EOF"goto jumpIfTrue"n"goto retrieve 1 2 goto add"n"goto store 15"n"goto retrieve 2 goto modulus 0 goto areEqual"f"goto jumpIfTrue 3"n"goto retrieve 2 goto modulus 0 goto areNotEqual"b"goto jumpIfTrue"Fizz"1 goto print goto b t:3"n"goto retrieve 2 goto modulus 0 goto areEqual"l"goto jumpIfTrue"n"goto retrieve 1 goto print goto l b:5"n"goto retrieve 2 goto modulus 0 goto areNotEqual"t"goto jumpIfTrue"Buzz"1 goto print goto l f:"FizzBuzz"1 goto print goto l

Requires a newline at the end, cause otherwise the interpreter throws a hissy fit.

Spaghetti is a stack based language that promotes using goto extensively. That means, every single operation you use requires a goto statement along with it.

That being said, this took a while.

Commented version is at the Spaghetti examples.

Try it on the online interpreter! (Code must be pasted in)

\$\endgroup\$
3
\$\begingroup\$

Python 3, 88 85 77 73 bytes

i=0
exec("i+=1;print(i%3*i%5and i or(i%3<1)*'Fizz'+(i%5<1)*'Buzz');"*100)

Try it online!

\$\endgroup\$
1
3
\$\begingroup\$

GNU AWK, 1 input byte + 60 bytes = 61 bytes

An approach different from Cabbie407's, that golfed 2 bytes off thanks to the more flexible parsing of the GNU's implementation. Still needs one EOF input.

END{for(;++n<101;print i?i:n)i=(n%3?e:"Fizz")(n%5?e:"Buzz")}

Try it online!

END              # starts after commanding the EOF (Ctrl+D).
{
for(;
    ++n<101;     # the _n_ variable is started here on the conditional, at the value 1.
    print i?i:n  # in the end of each loop, prints _i_ if non-null, or _n_.
   )
      i=(n%3?e:"Fizz")(n%5?e:"Buzz")
      # two ternary conditionals that concatenates Fizz and Buzz accordingly.
      # by the way, _e_ is a not assigned variable, which will return a null string ("").
      # if n != 0 (mod 15), then _i_ will return null at the print statement above.
}

For no input, use the BEGIN pattern instead (62 bytes total):

BEGIN{for(;++n<101;print i?i:n)i=(n%3?e:"Fizz")(n%5?e:"Buzz")}
\$\endgroup\$
3
\$\begingroup\$

jq, 45 bytes

range(100)+1|(1-.%3)*"fizz"+(1-.%5)*"buzz"//.
# explanation
range(100)+1| # for each number in range 0-99 + 1
      . % 3 ) #   the current number modulo 3
 ( 1 -        #   the important thing is this gives 1 for 0 and an invalid
              #   number (0 or negative) for any positive number
       *"fizz"#   "fizz" repeated that many times. For a negative or 0 number
              #   this returns null
 + ..."buzz"  #   concatenated with the same thing but for buzz.
              #   null + anything is that thing, so for a number not divisible by
              #   3 or 5 this returns null
   // .       #   if the result is null, the number itself
              # implicit output

For best results run with jq -rn '...' | less.

\$\endgroup\$
3
\$\begingroup\$

Turing Machine Code, 5743 bytes

Should note that Turing Machine Code doesn't process newlines/carriage returns. So everything is necessarily on one line. Thus this may not be, by strict interpretation of the rules, a competing answer due to the nature of the language.

0 * * * 1
1 * 1 r #
# * # * f
f * * l f
f 1 1 l !
f 2 2 l "
f 3 3 l £
f 4 4 l $
f 5 5 l %
f 6 6 l ^
f 7 7 l &
f 8 8 l `
f 9 9 l (
f 0 0 l )
f F F l f
f i i l f
f z z l f
f B B l f
f u u l f
) 1 1 * ¬
) 2 2 * -
) 3 3 * =
) 4 4 * +
) 5 5 * {
) 6 6 * }
) 7 7 * [
) 8 8 * ]
) 9 9 * :
! _ _ r '
! 1 1 r @
! 2 2 * ~
! 3 3 r \
! 4 4 r /
! 5 5 * ,
! 6 6 r .
! 7 7 r <
! 8 8 * >
! 9 9 r ?
" _ _ r a
" 1 1 * b
" 2 2 r c
" 3 3 r d
" 4 4 * e
" 5 5 r ƒ
" 6 6 r g
" 7 7 * h
" 8 8 r ï
" 9 9 r j
£ _ _ r k
£ 1 1 r l
£ 2 2 r m
£ 3 3 * n
£ 4 4 r o
£ 5 5 r p
£ 6 6 * q
£ 7 7 r r
£ 8 8 r s
£ 9 9 * t
$ _ _ r ü
$ 1 1 r v
$ 2 2 * w
$ 3 3 r x
$ 4 4 r y
$ 5 5 * ž
$ 6 6 r A
$ 7 7 r Ɓ
$ 8 8 * C
$ 9 9 r D
% _ _ r E
% 1 1 * Ϝ
% 2 2 * G
% 3 3 * H
% 4 4 * I
% 5 5 * J
% 6 6 * K
% 7 7 * L
% 8 8 * M
% 9 9 * N
^ _ _ r O
^ 1 1 r P
^ 2 2 r Q
^ 3 3 * R
^ 4 4 r S
^ 5 5 r T
^ 6 6 * U
^ 7 7 r V
^ 8 8 r W
^ 9 9 * X
& _ _ r Y
& 1 1 r Z
& 2 2 * α
& 3 3 r β
& 4 4 r γ
& 5 5 * δ
& 6 6 r ε
& 7 7 r ζ
& 8 8 * η
& 9 9 r θ
` _ _ r ι
` 1 1 * κ
` 2 2 r λ
` 3 3 r μ
` 4 4 * ν
` 5 5 r ξ
` 6 6 r ο
` 7 7 * π
` 8 8 r ρ
` 9 9 r ς
( _ _ r σ
( 1 1 r τ
( 2 2 r υ
( 3 3 * φ
( 4 4 r χ
( 5 5 r ψ
( 6 6 * ω
( 7 7 r Α
( 8 8 r Β
( 9 9 * Γ
@ * * r @
@ # _ r Δ
Δ _ 1 r Ε
Ε _ 2 r F
' * * r '
' # _ r 2
2 _ 2 r #
~ * * r ~
~ 2 _ r ~
~ 1 _ r ~
~ # _ r Ζ
Ζ _ 2 r 2
\ * * r \
\ # _ r Η
Η _ 3 r 2
/ * * r /
/ # _ r Θ
Θ _ 4 r Ε
, * * r ,
, 5 _ r ,
, 1 _ r ,
, # _ r Ι
Ι _ 5 r 2
. * * r .
. # _ r Κ
Κ _ 6 r 2
< * * r <
< # _ r Λ
Λ _ 7 r Ε
> * * r >
> 8 _ r >
> 1 _ r >
> # _ r Μ
Μ _ 8 r 2
? * * r ?
? # _ r Ν
Ν _ 9 r 2
a * * r a
a # _ r Ξ
Ξ _ 3 r F 
3 _ 3 r #
b * * r b
b 1 _ r b
b 2 _ r b
b # _ r Ο
Ο _ 1 r 3
c * * r c
c # _ r Π
Π _ 2 r 3
d * * r d
d # _ r Ρ
Ρ _ 3 r Ξ
e * * r e
e 4 _ r e
e 2 _ r e
e # _ r Σ
Σ _ 4 r 3
ƒ * * r ƒ
ƒ # _ r Τ
Τ _ 5 r 3
g * * r g
g # _ r Υ
Υ _ 6 r Ξ
h * * r h
h 7 _ r h
h 2 _ r h
h # _ r Φ
Φ _ 7 r 3
ï * * r ï
ï # _ r Χ
Χ _ 8 r 3
j * * r j
j # _ r Ψ
Ψ _ 9 r Ξ
k * * r k
k 3 _ r k
k # _ r 4
4 _ 4 r #
Ω _ 4 r F
l * * r l
l # _ r ¤
¤ _ 1 r 4
m * * r m
m # _ r ¥
¥ _ 2 r Ω
n * * r n
n 3 _ r n
n # _ r ¦
¦ _ 3 r 4
o * * r o
o # _ r ¨
¨ _ 4 r 4
p * * r p
p # _ r ©
© _ 5 r Ω
q * * r q
q 6 _ r q
q 3 _ r q
q # _ r ª
ª _ 6 r 4
r * * r r
r # _ r «
« _ 7 r 4
s * * r s
s # _ r ®
® _ 8 r Ω
t * * r t
t 9 _ r t
t 3 _ r t
t # _ r °
° _ 9 r 4
ü * * r ü
ü # _ r ±
± _ 5 r B 
v * * r v
v # _ r ²
² _ 1 r ³
³ _ 5 r Ƒ
5 _ 5 r #
w * * r w
w 2 _ r w
w 4 _ r w
w # _ r ¶
¶ _ 2 r ±
x * * r x
x # _ r ·
· _ 3 r ±
y * * r y
y # _ r ¸
¸ _ 4 r ³
ž * * r ž
ž 5 _ r ž
ž 4 _ r ž
ž # _ r ¹
¹ _ 5 r ±
A * * r A
A # _ r »
» _ 6 r ±
Ɓ * * r Ɓ
Ɓ # _ r ¼
¼ _ 7 r ³
C * * r C
C 8 _ r C
C 4 _ r C
C # _ r ½
½ _ 8 r ±
D * * r D
D # _ r ¾
¾ _ 9 r ±
E * * r E
E # _ r ¿
E 5 _ r E
¿ _ 6 r F 
6 _ 6 r #
Ϝ * * r Ϝ
Ϝ 1 _ r Ϝ
Ϝ 5 _ r Ϝ
Ϝ # _ r À
À _ 1 r 6
G * * r G
G 2 _ r G
G 5 _ r G
G # _ r Á
Á _ 2 r 6
H * * r H
H 3 _ r H
H 5 _ r H
H # _ r Â
 _ 3 r ¿
I * * r I
I 4 _ r I
I 5 _ r I
I # _ r Ã
à _ 4 r 6
J * * r J
J 5 _ r J
J # _ r Ä
Ä _ 5 r 6
K * * r K
K 6 _ r K
K 5 _ r K
K # _ r Å
Å _ 6 r ¿
L * * r L
L 7 _ r L
L 5 _ r L
L # _ r Æ
Æ _ 7 r 6
M * * r M
M 8 _ r M
M 5 _ r M
M # _ r Ç
Ç _ 8 r 6
N * * r N
N 9 _ r N
N 5 _ r N
N # _ r È
È _ 9 r ¿
O * * r O
O 6 _ r O
O # _ r 7
7 _ 7 r #
É _ 7 r F
P * * r P
P # _ r Ê
Ê _ 1 r 7
Q * * r Q
Q # _ r Ë
Ë _ 2 r É
R * * r R
R 3 _ r R
R 6 _ r R
R # _ r Ì
Ì _ 3 r 7
S * * r S
S # _ r Í
Í _ 4 r 7
T * * r T
T # _ r Ï
Ï _ 5 r É
U * * r U
U 6 _ r U
U # _ r Ð
Ð _ 6 r 7
V * * r V
V # _ r Ñ
Ñ _ 7 r 7
W * * r W
W # _ r Ò
Ò _ 8 r É
X * * r X
X 9 _ r X
X 6 _ r X
X # _ r Ó
Ó _ 9 r 7
Y * * r Y
Y # _ r 8
8 _ 8 r #
Z * * r Z
Z # _ r Ô
Ô _ 1 r Õ
Õ _ 8 r F
α * * r α
α 2 _ r α
α 7 _ r α
α # _ r Ö
Ö _ 2 r 8
β * * r β
β # _ r ×
× _ 3 r 8
γ * * r γ
γ # _ r Ø
Ø _ 4 r Õ
δ * * r δ
δ 5 _ r δ
δ 7 _ r δ
δ # _ r Ù
Ù _ 5 r 8
ε * * r ε
ε # _ r Ú
Ú _ 6 r 8
ζ * * r ζ
ζ # _ r Û
Û _ 7 r Õ
η * * r η
η 8 _ r η
η 7 _ r η
η # _ r Ü
Ü _ 8 r 8
θ * * r θ
θ # _ r Ý
Ý _ 9 r 8
ι * * r ι
ι # _ r Ā
Ā _ 9 r F 
9 _ 9 r #
κ * * r κ
κ 1 _ r κ
κ 8 _ r κ
κ # _ r Ă
Ă _ 1 r 9
λ * * r λ
λ # _ r Ą
Ą _ 2 r 9
μ * * r μ
μ # _ r Ć
Ć _ 3 r Ā
ν * * r ν
ν 4 _ r ν
ν 8 _ r ν
ν # _ r Ĉ
Ĉ _ 4 r 9
ξ * * r ξ
ξ # _ r Ċ
Ċ _ 5 r 9
ο * * r ο
ο # _ r Đ
Đ _ 6 r Ā
π * * r π
π 7 _ r π
π 8 _ r π
π # _ r Ē
Ē _ 7 r 9
ρ * * r ρ
ρ # _ r Ĕ
Ĕ _ 8 r 9
ς * * r ς
ς # _ r Ė
Ė _ 9 r Ā
Č _ 0 r #
σ * * r σ
σ # _ r Ę
σ 9 _ r σ
Ę _ 1 r Ď
Ď _ 0 r B
τ * * r τ
τ # _ r Ě
Ě _ 2 r Ď
υ * * r υ
υ # _ r Ĝ
Ĝ _ 3 r Ğ
Ğ _ 0 r Ƒ
φ * * r φ
φ 3 _ r φ
φ 9 _ r φ
φ # _ r Ġ
Ġ _ 4 r Ď
χ * * r χ
χ # _ r Ģ
Ģ _ 5 r Ď
ψ * * r ψ
ψ # _ r Ĥ
Ĥ _ 6 r Ğ
ω * * r ω
ω # _ r Ħ
ω 6 _ r ω
ω 9 _ r ω
Ħ _ 7 r Ď
Α * * r Α
Α # _ r Ĩ
Ĩ _ 8 r Ď
Β * * r Β
Β # _ r Ī
Ī _ 9 r Ğ
Γ * * r Γ
Γ 9 _ r Γ
Γ # _ r Ĭ
Ĭ _ B r Į
Į _ u r İ
İ _ z r IJ
IJ _ z r halt
Ĵ _ 1 r #
Ķ _ 1 r F
¬ * * r ¬
¬ 1 _ r ¬
¬ 0 _ r ¬
¬ # _ r Ĺ
Ĺ _ 1 r Ĵ
- * * r -
- 2 _ r -
- 0 _ r -
- # _ r Ļ
Ļ _ 2 r Ķ
= * * r =
= 3 _ r =
= 0 _ r =
= # _ r Ľ
Ľ _ 3 r Ĵ
+ * * r +
+ 4 _ r +
+ 0 _ r +
+ # _ r Ŀ
Ŀ _ 4 r Ĵ
{ * * r {
{ 5 _ r {
{ 0 _ r {
{ # _ r Ł
Ł _ 5 r Ķ
} * * r }
} 6 _ r }
} 0 _ r }
} # _ r Ń
Ń _ 6 r Ĵ
[ * * r [
[ 7 _ r [
[ 0 _ r [
[ # _ r Ň
Ň _ 7 r Ĵ
] * * r ]
] 8 _ r ]
] 0 _ r ]
] # _ r Ņ
Ņ _ 8 r Ķ
: * * r :
: 9 _ r :
: 0 _ r :
: # _ r Ŋ
Ŋ _ 9 r Ĵ
F _ F r i
i _ i r ȥ
ȥ _ z r ź
ź _ z r #
Ƒ _ F r í
í _ i r ż
ż _ z r ƶ
ƶ _ z r B
B _ B r u
u _ u r z
z _ z r ź

Try it online!

\$\endgroup\$
3
\$\begingroup\$

Squire, 92 bytes

n=N whilst C>n{t=""n=n+I if!(n%3){t="Fizz"}if!(n%V){t=t+"Buzz"}proclaim((t||arabic(n))+"
")}

Hear ye, hear ye! Unbeknownst to some, Sampersand hath also created Squire, a companion language to ye lowly language Knight. Squire hath many possessions, but alas, it doth not golfeth as well as its brethren. Thou shalt check it out as well, though.

I cannot provideth thee with a demo link yet as the interpreter is a very lengthy incantation.

Ungolfeth:

# Createth a variable known by most as "n",
# He shalt begin his journey as a mere
# peasant with naught but the value zero.
# (Behold! Squire permits thee to write numbers
# in Roman numerals)
n = N
# Loop thine program unto n approacheth 100
whilst C > n {
    # Lo! I spotteth another variable,
    # who goes by the name of "t".
    # It shall start off as a lonely empty string.
    t = ""
    # Increase n's wealth by bestowing upon it the number one
    n = n + I
    # If n divideth evenly into 3...
    if !(n % 3) {
        # Replaceth t with the string "Fizz"
        t = "Fizz"
    }
    # If n also divideth evenly into 5...
    if !(n % V) {
        # Accompany t with the string "Buzz"
        t = t + "Buzz"
    }
    # Proclaim to ye standard output...
    proclaim(
        # Either...
        (
           #  t if it is not a lonely empty string...
           t
           # or n, converteth to ye foreign Arabic
           # number system, used in lands afar.
           || arabic(n)
        )
        # Appendeth upon it a newline to start
        # another journey.
        + "\n"
    )
}

A more favorable program is as follows:

n=N whilst C>n{t=""n=n+I if!(n%III){t="Fizz"}if!(n%V){t=t="Buzz"}proclaim((t||string(n))+"
")}

This program useth Roman numerals, but nay, thine great quest beseecheth that one must outputeth thy program using this unusual number system.

\$\endgroup\$
3
\$\begingroup\$

Perl 5 (ppencode-compatible), 1232 690 bytes

Today I learned that and has higher precidence than or or xor; I suffered from making a proper control flow

eval q y eval q x ord or return cos while chop and chop and chop x and print chr ord uc qw q for q and print chr ord q tie gt and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc y xor eval q y print uc chr ord q dbmopen and and print chr ord q dump and and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos if length q q s s q eq chr ord reverse length or not chr ord reverse length y or eval q x print length unless length q q s s q eq chr ord reverse length or not chr ord reverse length x xor print chr hex qw q and q while s qq q and length ne ord qw q eq

Try it online!

How it works

# fizz part
eval q y
   # if(length%3==0)
   eval q x
      # instead of length or return 1
      ord or return cos
   while
      # instead of s/...//
      chop and chop and chop
   x and
 
   # print 'Fizz'
   print chr ord uc qw q for q and
   print chr ord q tie gt and
   print chr length q else x oct oct ord q eq le and
   print chr length q else x oct oct ord q eq le and

   # for truthy
   return cos
for
   # instead of $_
   uc
y

xor

# buzz part
eval q y
   # print 'Buzz'
   print uc chr ord q dbmopen and and
   print chr ord q dump and and
   print chr length q else x oct oct ord q eq le and
   print chr length q else x oct oct ord q eq le and

   # for truthy
   return cos
if
   # instead of length%5, /[05]$/
   length q q s s q eq chr ord reverse length or
   not chr ord reverse length
y

or

# this block is done when length%15==0 or length%3&&length%5
eval q x
   print length
unless
   # instead of length%5
   length q q s s q eq chr ord reverse length or
   not chr ord reverse length
x

xor

# newline
print chr hex qw q and q


while
   s qq q and

   # ord qw q eq == 101
   length ne ord qw q eq

Previous

eval q y eval q kill and length or return cos while s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and ok and print chr ord uc qw q for q and print chr ord q tie gt and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and print uc chr ord q dbmopen and and print chr ord q dump and and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc y or eval q y eval q kill and length or return cos while s q qq and s q qq and s q qq and s q qq and s q qq and ok and print uc chr ord q dbmopen and and print chr ord q dump and and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc y or eval q y eval q kill and length or return cos while s q qq and s q qq and s q qq and ok and print chr ord uc qw q for q and print chr ord q tie gt and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc y or print length xor print chr length q q x x x x eq while s qq q and length ne ord qw q eq

Try it online!

Explained

# fizzbuzz part
eval q y
   # length%15==0?
   eval q k
         ill and length or return cos
      while
s q qq and s q qq and s q qq and
s q qq and s q qq and s q qq and
s q qq and s q qq and s q qq and
s q qq and s q qq and s q qq and
s q qq and s q qq and s q qq and o
   k and
   # then print FizzBuzz, as in first ppencode
   print chr ord uc qw q for q and
   print chr ord q tie gt and
   print chr length q else x oct oct ord q eq le and
   print chr length q else x oct oct ord q eq le and
   print uc chr ord q dbmopen and and
   print chr ord q dump and and
   print chr length q else x oct oct ord q eq le and
   print chr length q else x oct oct ord q eq le and
   # cos is for TRUTHY
   return cos
 # don't change $_ outside 
 for uc
# buzz part, like above
y or eval q y
   eval q kill and length or return cos while s q qq and s q qq and s q qq and s q qq and s q qq and ok and print uc chr ord q dbmopen and and print chr ord q dump and and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc
# fizz part, like above
y or eval q y
   eval q kill and length or return cos while s q qq and s q qq and s q qq and ok and print chr ord uc qw q for q and print chr ord q tie gt and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc
# no special strings
y or print length
# print LF
xor print chr length q q x x x x eq
# pretty familiar, isn't it?
while s qq q and length ne ord qw q eq
\$\endgroup\$
0
3
\$\begingroup\$

Javastack, 123 bytes

100 times context 1 add "Buzz"context 1 add 5 mod 0 equal repeat "Fizz"context 1 add 3 mod 0 equal repeat add logicor print

Try it online!

Context is everything. This is different to Wasif's Javastack answer because it uses a loop instead of a map, as well as extensive use of the context variable (totally not inspired by a certain golfing language made by a certain cg user with Flowey as his pfp).

Roughly equivalent to:

100ʁ ( n 1+ `Fizz` n 1+ 3 ḋt ¬ẋ `Buzz` n 1+ 5 ḋt ¬ẋ + ⟇, ) 

in vyxal.

You don't know how nice it was to write a Javastack answer without restrictions after 13 rounds of C&R.

\$\endgroup\$
1
  • \$\begingroup\$ I see. Don't worry, there'll be a #10... \$\endgroup\$
    – emanresu A
    Aug 8 '21 at 19:56
3
\$\begingroup\$

HTML & CSS, 502 bytes

body{counter-reset:n}
p::after{counter-increment:n;content:counter(n)}
p:nth-child(3n)::after{content:"Fizz"}
p:nth-child(5n)::after{content:"Buzz"}
p:nth-child(15n)::after{content:"FizzBuzz"}
<p><p><p><p><p><p><p><p><p><p>
<p><p><p><p><p><p><p><p><p><p>
<p><p><p><p><p><p><p><p><p><p>
<p><p><p><p><p><p><p><p><p><p>
<p><p><p><p><p><p><p><p><p><p>
<p><p><p><p><p><p><p><p><p><p>
<p><p><p><p><p><p><p><p><p><p>
<p><p><p><p><p><p><p><p><p><p>
<p><p><p><p><p><p><p><p><p><p>
<p><p><p><p><p><p><p><p><p><p>

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Nice answer! You don't need the <div> elements and you can skip the closing </p> tags as well, it should still render fine. \$\endgroup\$
    – emanresu A
    Nov 22 '21 at 2:53
  • \$\begingroup\$ Thanks @emanresuA. I still needed an element to apply the counter-reset to but it could just have been the body. Removing the closing </p> helped shave off a lots of bytes. \$\endgroup\$ Nov 22 '21 at 9:02
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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]);}}
\$\endgroup\$
2
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ 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. \$\endgroup\$
    – Brian J
    Sep 25 '15 at 13:13
2
\$\begingroup\$

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
\$\endgroup\$
5
  • \$\begingroup\$ it is possible to save some bytes by reducing the amount of indentation. (1 space is sufficient) \$\endgroup\$
    – Mohammad
    Sep 27 '15 at 18:12
  • 1
    \$\begingroup\$ @Mhmd it's probably actually tabs, SE converts them to 4 spaces. \$\endgroup\$ Sep 27 '15 at 22:18
  • \$\begingroup\$ 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 \$\endgroup\$ Sep 27 '15 at 22:19
  • 1
    \$\begingroup\$ oh, but you can change ==0 to <1 everywhere it appears \$\endgroup\$ Sep 27 '15 at 22:58
  • 1
    \$\begingroup\$ This 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. \$\endgroup\$
    – Skyler
    Oct 26 '15 at 13:47
2
\$\begingroup\$

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);}}
\$\endgroup\$
0
2
\$\begingroup\$

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

\$\endgroup\$
2
\$\begingroup\$

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!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You 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. \$\endgroup\$
    – Najkin
    Sep 29 '15 at 15:56
2
\$\begingroup\$

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
\$\endgroup\$
1
  • 1
    \$\begingroup\$ IFIMOD3=0ANDIMOD5=0 -> IFIMOD15=0? I think MSX BASIC could be tokenized too, which would decrease your byte count. \$\endgroup\$
    – lirtosiast
    Sep 30 '15 at 14:53
1
3 4
5
6 7
12

Your Answer

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

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