196
\$\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
  • 76
    \$\begingroup\$ A "vanilla fizzbuzz" sounds delicious. \$\endgroup\$ Sep 25, 2015 at 15:12

416 Answers 416

1
\$\begingroup\$

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

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

Ruby, 68 65 bytes

q='Buzz';(1..100).map &->e{p e%3<1?'Fizz'+(e%5<1?q:''):e%5<1?q:e}
\$\endgroup\$
2
  • \$\begingroup\$ If you've made your program one byte shorter, you'll want to change the header to 64 bytes :) \$\endgroup\$ May 16, 2017 at 21:05
  • 1
    \$\begingroup\$ Why map &->e{ and not map{|e| ? \$\endgroup\$
    – daniero
    Jun 5, 2017 at 21:19
1
\$\begingroup\$

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
]
\$\endgroup\$
2
  • \$\begingroup\$ Hmm nice language... Is there an online interpreter or is it all offline? \$\endgroup\$
    – Beta Decay
    May 27, 2017 at 16:29
  • \$\begingroup\$ @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. \$\endgroup\$
    – daniero
    May 27, 2017 at 16:41
1
\$\begingroup\$

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!

\$\endgroup\$
1
  • \$\begingroup\$ What about this? \$\endgroup\$
    – User123
    Jun 6, 2021 at 21:06
1
\$\begingroup\$

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.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ "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 :) \$\endgroup\$
    – Aaron
    Aug 25, 2017 at 15:46
  • \$\begingroup\$ You don't need //; with integer arguments, / performs integer division in Python 2. -~i saves an additional byte. tio.run/##K6gsycjPM/r/Py2/… \$\endgroup\$
    – Dennis
    Aug 25, 2017 at 15:49
1
\$\begingroup\$

AsciiDots, 152 bytes

 #
/$""
\~\
 @\-\
[=]@*-\
/@----*-~&
|0/---*[>]
|@\<>$_"Buzz"@1)
|*-~/ /-/
||[%]-\>#100)
v\-*#5*/
|.//
| \<>$_"Fizz"@1)
|/-~/
@|[%]-\
0\-*#3/
*-[+]
\#1/

Try it online!

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

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

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')+'
')
\$\endgroup\$
1
\$\begingroup\$

Funky, 59 bytes

for(i=1i<100i++)print((("Fizz"*1&!i%3)+("Buzz"*1&!i%5))ori)

Try it online!

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

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.

\$\endgroup\$
1
  • \$\begingroup\$ Answers are not required to be in the latest version of their language, so this is still valid. \$\endgroup\$ Apr 9, 2020 at 2:22
1
\$\begingroup\$

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

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!

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

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");
    }
}
\$\endgroup\$
1
  • \$\begingroup\$ This is not ok: main(){while(i++<100){(i%3<1&&p("fizz"))+(i%5<1&&p("buzz"))<1&&p("%d",i);p("\n");} ? \$\endgroup\$
    – user58988
    Dec 7, 2017 at 19:01
1
\$\begingroup\$

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!

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

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!

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

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

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

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)
\$\endgroup\$
0
1
\$\begingroup\$

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

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

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.

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

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

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!

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

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!

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

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.

\$\endgroup\$
1
  • \$\begingroup\$ 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. \$\endgroup\$
    – Phlarx
    Mar 29, 2018 at 21:31
1
\$\begingroup\$

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!

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

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
]
\$\endgroup\$
6
  • \$\begingroup\$ This actually doesn't look like such a bad language \$\endgroup\$
    – ASCII-only
    Apr 20, 2018 at 13:02
  • \$\begingroup\$ @ASCII-only Thank you! \$\endgroup\$ Apr 20, 2018 at 13:05
  • \$\begingroup\$ There's only one problem: this is nothing like Foo :P \$\endgroup\$
    – ASCII-only
    Apr 20, 2018 at 13:16
  • \$\begingroup\$ @ASCII-only This is strikingly like foo, actually. The only thing in this answer unlike foo are the new while loops [...] \$\endgroup\$ Apr 20, 2018 at 13:18
  • \$\begingroup\$ >_> 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 \$\endgroup\$
    – ASCII-only
    Apr 20, 2018 at 13:33
1
\$\begingroup\$

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

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

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

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.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ General golf tip that is surprisingly pythonic: w!='' can be w. \$\endgroup\$ Jul 18, 2018 at 11:07
  • \$\begingroup\$ Though for a more golfed version of the straight-forward approach, see this answer. \$\endgroup\$ Jul 18, 2018 at 11:12
1
\$\begingroup\$

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

Python 3, 62 bytes

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

Try it online!

\$\endgroup\$

Your Answer

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

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