194
\$\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\$
14
  • 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, 2015 at 20:47
  • 1
    \$\begingroup\$ @AShelly Only when running \$\endgroup\$
    – Beta Decay
    Sep 24, 2015 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, 2015 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, 2015 at 0:50
  • 75
    \$\begingroup\$ A "vanilla fizzbuzz" sounds delicious. \$\endgroup\$ Sep 25, 2015 at 15:12

413 Answers 413

1
10 11 12 13
14
0
\$\begingroup\$

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.

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

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
\$\endgroup\$
2
  • \$\begingroup\$ you say function a in the ungolfed, do you mean function F? \$\endgroup\$ May 15, 2017 at 23:39
  • \$\begingroup\$ 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 \$\endgroup\$ May 15, 2017 at 23:40
0
\$\begingroup\$

///, 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
\$\endgroup\$
1
  • \$\begingroup\$ 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 \$\endgroup\$ May 15, 2017 at 4:34
0
\$\begingroup\$

Micro, 72 bytes

:i{i1+:i"":d
i3/i3%=if("Fizz":d,)
i5/i5%=if(d"Buzz"+:d,)
d:\i100=if(,a)}
\$\endgroup\$
0
\$\begingroup\$

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!

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

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.

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

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!

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

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!

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

05AB1E, 25 bytes

тLv”FizzÒÖ”#y3 5‚ÖÏJy‚éθ,

Try it online!

I figured I'd add a fourth 05AB1E answer to this challenge. This uses my favourite "vectorise is-divisible and then repeat the fizbuzz list accordingly" approach.

Explained

тLv”FizzÒÖ”#y3 5‚ÖÏJy‚éθ,
тL                        # The range 1 .. 100
  v                       # For each N in that range:
   ”FizzÒÖ”#              #     Push the list ["Fizz", "Buzz"]
            y3 5‚Ö        #     Push N % [3, 5] == 0 (vectorised)
                  Ï       #     "Multiply" the two lists as you would in Vyxal
                   J      #     And concatenate that into a single string
                    y‚    #     And pair that with N
                      é   #     Sorting that by length, so that the value we want is always last
                       θ, #     And print it with a newline
\$\endgroup\$
0
\$\begingroup\$

D, 115 bytes

import std;void main(){string x;for(int i;i++<100;x=((i%3?"":"Fizz")~(i%5?"":"Buzz")),writeln(x?x:i.to!string)){};}

Try it online!

Adapted from this code:

import std;void main(){auto fizzbuzz(in uint i){string r;if(i%3==0)r~="Fizz";if(i%5==0)r~="Buzz";if(r.length==0)r~=i.to!string;return r;}enum r=1.iota(101).map!fizzbuzz;r.each!writeln;}
\$\endgroup\$
0
\$\begingroup\$

Fortran (GFortran), 187 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
ENDIF;ENDDO;END

Try it online!

\$\endgroup\$
1
0
\$\begingroup\$

JavaScript (code.golf), 62 56 bytes

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

This is a code.golf version, which allows usage of print instead console.log.

Here is the un-code.golfed version:

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

Nim, 72 bytes

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

Try it online!

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

Pascal (FPC), 180 bytes

program f(o);var i:integer;begin for i:=1to 100do if i mod 15=0then writeln('FizzBuzz')else if i mod 3=0then writeln('Fizz')else if i mod 5=0then writeln('Buzz')else writeln(i)end.

Try it online!

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

Morse Code, 1777 bytes

.---- / ..--- / ..-. .. --.. --.. / ....- / -... ..- --.. --.. / ..-. .. --.. --.. / --... / ---.. / ..-. .. --.. --.. / -... ..- --.. --.. / .---- .---- / ..-. .. --.. --.. / .---- ...-- / .---- ....- / ..-. .. --.. --.. -... ..- --.. --.. / .---- -.... / .---- --... / ..-. .. --.. --.. / .---- ----. / -... ..- --.. --.. / ..-. .. --.. --.. / ..--- ..--- / ..--- ...-- / ..-. .. --.. --.. / -... ..- --.. --.. / ..--- -.... / ..-. .. --.. --.. / ..--- ---.. / ..--- ----. / ..-. .. --.. --.. -... ..- --.. --.. / ...-- .---- / ...-- ..--- / ..-. .. --.. --.. / ...-- ....- / -... ..- --.. --.. / ..-. .. --.. --.. / ...-- --... / ...-- ---.. / ..-. .. --.. --.. / -... ..- --.. --.. / ....- .---- / ..-. .. --.. --.. / ....- ...-- / ....- ....- / ..-. .. --.. --.. -... ..- --.. --.. / ....- -.... / ....- --... / ..-. .. --.. --.. / ....- ----. / -... ..- --.. --.. / ..-. .. --.. --.. / ..... ..--- / ..... ...-- / ..-. .. --.. --.. / -... ..- --.. --.. / ..... -.... / ..-. .. --.. --.. / ..... ---.. / ..... ----. / ..-. .. --.. --.. -... ..- --.. --.. / -.... .---- / -.... ..--- / ..-. .. --.. --.. / -.... ....- / -... ..- --.. --.. / ..-. .. --.. --.. / -.... --... / -.... ---.. / ..-. .. --.. --.. / -... ..- --.. --.. / --... .---- / ..-. .. --.. --.. / --... ...-- / --... ....- / ..-. .. --.. --.. -... ..- --.. --.. / --... -.... / --... --... / ..-. .. --.. --.. / --... ----. / -... ..- --.. --.. / ..-. .. --.. --.. / ---.. ..--- / ---.. ...-- / ..-. .. --.. --.. / -... ..- --.. --.. / ---.. -.... / ..-. .. --.. --.. / ---.. ---.. / ---.. ----. / ..-. .. --.. --.. -... ..- --.. --.. / ----. .---- / ----. ..--- / ..-. .. --.. --.. / ----. ....- / -... ..- --.. --.. / ..-. .. --.. --.. / ----. --... / ----. ---.. / ..-. .. --.. --.. / -... ..- --.. --..
\$\endgroup\$
0
\$\begingroup\$

Prolog (SWI), 225 229 165 bytes

f(N,'FizzBuzz'):-N mod 15<1. f(N,'Fizz'):-N mod 3<1,N mod 5>0. f(N,'Buzz'):-N mod 3>0,N mod 5<1. f(N,N):-N mod 3>0,N mod 5>0. :-between(1,100,X),f(X,Y),\+writeln(Y).

Try it online!

Thanks to @JoKing (redundant init and h), I lost 64 bytes!

:-initialization m. f(N,'FizzBuzz'):-N mod 3=:=0,N mod 5=:=0. f(N,'Fizz'):-N mod 3=:=0,N mod 5=\=0. f(N,'Buzz'):-N mod 3=\=0,N mod 5=:=0. f(N,N):-N mod 3=\=0,N mod 5=\=0. m:-between(1,100,X),f(X,Y),write(Y),nl,fail,h(0). m:-h(1).

\$\endgroup\$
2
  • \$\begingroup\$ What is the point of the h calls? also the initialization part? Some simple golfing for 165 bytes (though it can be half the size) \$\endgroup\$
    – Jo King
    May 3, 2022 at 6:40
  • \$\begingroup\$ @JoKing Sorry, I'm not that good at Prolog. I got really into it one day but then lost interest in it. Thanks for the tip! \$\endgroup\$ May 3, 2022 at 16:16
0
\$\begingroup\$

Raku, 44 bytes

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

Try it online!

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

V (vlang.io), 137 bytes

fn main(){for i in 1..101{if i%15==0{println('FizzBuzz')}else if i%3==0{println('Fizz')}else if i%5==0{println('Buzz')}else{println(i)}}}

Try it online!

Ungolfed code:

fn main () {
  mut i := 1
  for i < 101 {
    match true {
      i % 15 == 0 {
        println('FizzBuzz')
      } i % 3 == 0 {
        println('Fizz')
      } i % 5 == 0 {
        println('Buzz')
      } else {
        println(i)
      }
    }
    i++
  }
}
\$\endgroup\$
0
\$\begingroup\$

Fig, \$31\log_{256}(96)\approx\$ 25.517 bytes

jcnnna100 5'"Buzz"3'FOa9+"Fizz"

Try it online!

Hmm yes irrational bytes. "It'll be shorter" they said. "It's the future of golf".

8.5 bytes longer than legitimate vybuzz, 5.5 more than Jelly, 15.5 more than the optimal vybuzz/Fact fizzbuzz.

Explained

jcnnna100 5'"Buzz"3'FOa9+"Fizz"
    na100 5'"Buzz"               # Every 5th item of the range [1, 100] replaced with "Buzz"
   n              3'             # To every 3rd item of that:
                        +"Fizz"  #   Prepend the word "Fizz"
                    FOa9         #   And remove all digits from it. This should just be FcD (because cD is allegedly all digits), but turns out that cD is [A-z0-9], which is allegedly what cN is supposed to be, but cN errors out. Thanks Seggan very cool.
jcn                              # Join all that on newlines
\$\endgroup\$
7
  • \$\begingroup\$ Not amused. After fixing about 8 bugs I got the n solution one char shorter smh \$\endgroup\$
    – Seggan
    Sep 8, 2022 at 2:29
  • \$\begingroup\$ this prints BuzzFizz \$\endgroup\$
    – naffetS
    Sep 8, 2022 at 3:30
  • \$\begingroup\$ @Seggan well the jokes on you because I got it 3 characters shorter \$\endgroup\$
    – lyxal
    Sep 8, 2022 at 3:53
  • \$\begingroup\$ Golfing in somebody else's language as a means of bragging about your own language is in very poor taste, IMO. \$\endgroup\$
    – DLosc
    Sep 8, 2022 at 4:15
  • \$\begingroup\$ @DLosc maybe, but in this case, it's more along the lines of friendly banter \$\endgroup\$
    – lyxal
    Sep 8, 2022 at 4:17
0
\$\begingroup\$

Convex, 35 bytes

A²´{__3%!"Fizz"*\5%!"Buzz"*+\e|}%N*

Try it online!

Why must older golfing languages not having automatically vectorising operations?

Explained

A²´{__3%!"Fizz"*\5%!"Buzz"*+\e|}%N*
A²´{                           }%   e# to the range [1, 100]:
    __                              e#   Triplicate the item
      3%!"Fizz"*                    e#   Repeat the string "Fizz" (!item % 3) times
                \5%!"Buzz"*         e#   Repeat the string "Buzz" (!item % 5) times
                           +\e|     e#   Add the two strings together and logical or with the item
                                 N* e# Join that on newlines
\$\endgroup\$
0
\$\begingroup\$

vemf, 33 bytes

d↨╕{╞"Fizz""Buzz"‼╞αó35,X·x≈?x◘αⁿ

A new language, a new fizzbuzz. 5 bytes longer than the one in the repo.

Explained

d↨╕{╞"Fizz""Buzz"‼╞αó35,X·x≈?x◘αⁿ
d↨╕{                               # To each number n in the range 1..100
                   αó35            # [n % 3 == 0, n % 5 == 0]
     "Fizz""Buzz"‼                 # ["Fizz" if n % 3 == 0, "Buzz" if n % 5 == 0]
                       ,           # flatten
                        X          # and store in variable x
                         ·x≈?      # is there stuff in x?
                             x◘αⁿ  # yes: return x, else: return str(n)    
\$\endgroup\$
0
\$\begingroup\$

Minecraft Function, 666 bytes

scoreboard objectives add c dummy
scoreboard players add c c 1
scoreboard players set 0 c 0
scoreboard players set 3 c 3
scoreboard players set 5 c 5
scoreboard players operation f c = c c
scoreboard players operation b c = c c
scoreboard players operation f c %= 3 c
scoreboard players operation b c %= 5 c
execute if score f c > 0 c if score b c > 0 c run tellraw @a {"score":{"name":"c","objective":"c"}}
execute if score f c = 0 c if score b c > 0 c run tellraw @a "Fizz"
execute if score f c > 0 c if score b c = 0 c run tellraw @a "Buzz"
execute if score f c = 0 c if score b c = 0 c run tellraw @a "FizzBuzz"
execute if score c c matches ..99 run function a:b

Must be run as a function named a in a data pack named b. I think this is about optimal for a scoreboard based solution.

Commented version:

# Create scoreboard to store variables
scoreboard objectives add c dummy
# Increment counter by 1 (starts at 0)
scoreboard players add c c 1
# Set constants 0, 3, and 5 for comparison and modulo
scoreboard players set 0 c 0
scoreboard players set 3 c 3
scoreboard players set 5 c 5

# Copy value of counter to f and b and modulo them by 3 and 5 respectively.
scoreboard players operation f c = c c
scoreboard players operation b c = c c
scoreboard players operation f c %= 3 c
scoreboard players operation b c %= 5 c

# If f and b are both > 0, print the counter
execute if score f c > 0 c if score b c > 0 c run tellraw @a {"score":{"name":"c","objective":"c"}}
# If f = 0 and b > 0, print Fizz
execute if score f c = 0 c if score b c > 0 c run tellraw @a "Fizz"
# If f > 0 and b > 0, print Buzz
execute if score f c > 0 c if score b c = 0 c run tellraw @a "Buzz"
# If both are 0 print FizzBuzz (Minecraft doesn't support string concatenation so this is necessary)
execute if score f c = 0 c if score b c = 0 c run tellraw @a "FizzBuzz"
# Run the function again if the counter is <= 99
execute if score c c matches ..99 run function a:b
\$\endgroup\$
0
\$\begingroup\$

sclin, 63 bytes

100I-a \; tap
"Fizz""Buzz", over3 5, % ! ** c>< dup \pop |# n>o

Try it on scline!

My collection grows once again

\$\endgroup\$
1
10 11 12 13
14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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