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

426 Answers 426

1
\$\begingroup\$

FALSE, 86 bytes

[\100*\/$100$@\/*-0=]m:1[$100>~][0\$3m;![\%1\"Fizz"]?$5m;![\%1\"Buzz"]?\0=[$.]?10,1+]#

Try it online!

Explanation

[\100*\/$100$@\/*-0=]m: Define Modulo Function
    [\100*\/ Divide number * 100 by the divisor to get decimals
    $100$@/* Get truncated result
    -0= Subtract to get decimal, if equal to 0, then the modulo is zero and return true. If not, return false as we don't care about the result
1 Put counter on stack
[$100>~] Check if number is greater than 100
[0\$3m;![\%1\"Fizz"]?$5m;![\%1\"Buzz"]?\0=[$.]?10,1+]# Do FizzBuzz if not
    [0\ Number to see if both % 3 and % 5 failed
    $3m;! Number % 3
    [\%1\"Fizz"]? If yes, do what is in brackets
        [\%1\ Set number to 1
        "Fizz"]? Print Fizz
    $5m;! Number % 5
    [\%1\"Buzz"]? If yes, do what is in brackets
        [\%1\ Set number to 1
        "Buzz"]? Print Buzz
    \0= Check if both modulo functions failed
    [$.]? If yes, do what is in brackets
        [$ Duplicate our counter so it doesn't get destroyed
        .]? Print the counter
    10, Print ASCII character 10 (line break)
    1+]# Increment counter

Could most likely be way better.

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

Canvas, 31 bytes

A2^{w3%0≡Fizz×y5%0≡Buzz×+:?O]yO

Try it here!

Okay seriously guys why is it that both ascii-art focused languages didn't already have a FizzBuzz? This uses my favourite FizzBuzz approach found in the Vyxal answer.

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

BRASCA, 81 bytes

1b1[x0aB:b3%0=[x`zziF`oooo1a0]xB:b5%0=[x`zzuB`oooo0A1+a]xA0=[xB:bn0]xB1+:bH1+<lo]

Try it online!

There'll be an explanation coming soon. The tio link is the interpreter split over the header and footer in such a way that the program can be entered into the code box.

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

Mouse-83/Mouse-2002, 73 bytes

1F:(F.Z4*1+<^0A:F.3\0=["Fizz"1A:]F.5\0=["Buzz"A.1+A:]A.0=[F.!]"!"F.1+F:)$

Try it online! Yet another fizzbuzz. Polyglots both versions listed and beats the current answer. The funny thing is that I came up with this independently of the other answer and managed to use the same approach.

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

Javascript, 99 bytes

This isn't a good, or small solution, but it works:

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

Explanation:

for (let i=1;i<101;i++) // Loop through, until reaching 100
{
    console.log(
    (i%3==0 // If I is a multiple of 3
    &&      // And
    i%5==0  // If I is a multiple of 5
    )?"FizzBuzz": // Print "FizzBuzzz"
    (i%3==0)?"Fizz":  // If I isn't either of those, check whether I is a multiple of 3, if so, print "Fizz"
    (i%5==0)?"Buzz" // If I isn't a multiple of 3, check whether I is a multiple of 5, if so, print "Buzz"
    :i // Else, just print i
    );
}
\$\endgroup\$
1
\$\begingroup\$

Myddin, 157 bytes

use std
var p=std.put
const main={
for var i=1;i<101;i++
match(i%3,i%5)
|(0,0):p("FizzBuzz\n")
|(0,_):p("Fizz\n")
|(_,0):p("Buzz\n")
|(_,_):p("{}\n",i)
;;;;}
\$\endgroup\$
1
\$\begingroup\$

ThumbGolf, 49 bytes

Machine code (little endian pairs):

2100 3101 0008 dec0 d003 b908 a303 de03
004a de6a b922 a305 de03 e003 6946 7a7a
b100 de21 de3a 2964 d1eb 4770 7542 7a7a
00

Commented assembly:

        // Include the ThumbGolf wrapper macros
        .include "thumbgolf.inc"
        .globl main
        .thumb_func
main:
        // Start the counter with zero and increment first.
        // It aligns better than incrementing at the bottom.
        movs    r1, #0
.Lloop:
        adds    r1, #1
.Lthree:
        // r0 = r1 % 3
        movs    r0, r1
        umodi   r0, 3   // udf #0300; .short 0xd003
        // if r0 == 0
        cbnz    r0, .Lten
        // if so print "Fizz"
        adr     r3, .Lfizz
        puts    r3      // udf #0003
.Lten:
        // do the same for Buzz
        // r2 = (r1 * 2) % 10, a.k.a. r1 % 5
        // we do this because umod.10 is a special narrow instruction :)
        lsls    r2, r1, #1
        umod.10 r2      // udf #0152
        cbnz    r2, .Lnum
        adr     r3, .Lbuzz
        puts    r3      // udf #0003
        // jump to the newline
        b       .Lnoprint

        // Normally, "Fizz" and "Buzz" are 5 byte strings due to the null
        // terminator, which SUCKS. This is because Thumb instructions MUST
        // be 2 byte aligned, and pool loads that are not 4 byte aligned are
        // annoying wide instructions.
        //
        // However, I have a trick up my sleeve.
        //
        // CBZ is encoded as so:
        //    |15 14 13 12|11|10| 9| 8| 7  6  5  4  3 |2  1  0|
        //    | 1  0  1  1| 0| 0| i| 1|      imm5     |  Rn   |
        // Let's focus on bits 0-7, which, since ARM is little endian, appear
        // first.
        //
        // imm5 is the offset in opcodes relative to 4 bytes after the current
        // instruction (a.k.a. where the PC is for dumb reasons). Technically,
        // there is a 6th bit in bit 9, but that is only for larger offsets.
        //
        // .Lnoprint is exactly 4 bytes after the instruction, so the offset
        // is zero:
        //   0 0 0 0 0 r r r
        // Now, for the register argument, if we set it to r0...
        //   0 0 0 0 0 0 0 0
        // Behold. A free null terminator.
        //
        // This is great, as it not only lets us cheat a byte in Fizz, but also,
        // it makes everything align perfectly so we don't need any wide adr
        // instructions. We can just put Buzz at the bottom of the file and it
        // will be 4 byte aligned as well.
.Lfizz:
        .ascii  "Fizz"  // null terminated by cbz encoding
.Lnum:
        // was r1 % 3 not zero (meaning did we not print Fizz?)
        cbz     r0, .Lnoprint
        // if so, print r1 as an integer
        puti    r1      // udf #0041
.Lnoprint:
        // putspc is a narrow instruction that prints one of 8 special characters,
        // one of which includes \n.
        putspc  '\n'    // udf #0072
        // loop while r1 != 100
        // replace with a register for variable length
        cmp     r1, #100
        bne     .Lloop
        // return
        bx      lr
.Lbuzz:
        .asciz  "Buzz"

My second submission in my brand new WIP ThumbGolf language, an ISA extension to Thumb-2.

It shows off both the new I/O instructions and the modulo instructions (with the special narrow encoding for 10).

That little hack by null terminating with cbz saves a lot, and it was really fun to figure out.

As mentioned in my cat program, this can be run on ARM Linux or QEMU by linking the ThumbGolf runtime. I don't have an online interpreter yet (and I doubt I could afford hosting one lul)

\$\endgroup\$
3
  • \$\begingroup\$ Actually, you should have based it on x86 machine code... So is ThumbGolf a RISC or a CISC? \$\endgroup\$
    – user99151
    Commented Feb 5, 2021 at 8:05
  • \$\begingroup\$ ThumbGolf is what I envision to be a "RISC golfing language". I am sticking to this limitation, even if it isn't gonna win any contests. \$\endgroup\$
    – EasyasPi
    Commented Feb 5, 2021 at 11:19
  • \$\begingroup\$ As I personally find golfing languages that let you answer a complex challenge in one byte ruin the whole point of golfing. 🤷‍♂️ \$\endgroup\$
    – EasyasPi
    Commented Feb 5, 2021 at 11:26
1
\$\begingroup\$

JavaScript: 76 bytes

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

Not the best solution we have, but not the worst either... The "nested" ternary operator adds either buzz or nothing to the fizz part depending on the results of the divisibility test.

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

///, 235 bytes

/(/\/\///%/111()/\\\\(p/1\/(x/%%%1(t/xxxxxxxxxx(>p^=)=^!)=$)vvt&@
^^!)=^=)=^^$v)v^|^^v)v1^v)av^^v)av^v)v^>(^/\(/>(>t/%&/&%(1&/1(%11@/@%11(1@/1(&p&(@p@(&/Fizz(@/Buzz(|p001(|(/0x/1\0(0p_1(0_/_(1p2(22/4(42/6(44/8(2p3(4p5(6p7(8p9(_(/=\=(==

Try it online!

There is already a /// answer, but it is pretty boring. I thought I would try to make a more algorithmic one, even though it is a little longer ;)

Ungolfed: Try it online!

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

Stax, 21 bytes

åS╬╕▌≡º$)ö;▀├Xè¶XΔ£≈♀

Run and debug it

Not sure why recursive's solution from the tutorial hasn't been posted here yet. Probably the most minimal fizzbuzz possible in stax.

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

Excel, 82 79 Bytes

=LET(x,ROW(1:100),a,IF(MOD(x,3),"","Fizz")&IF(MOD(x,5),"","Buzz"),IF(a="",x,a))

This wasn't valid when the question was asked.

Spreadsheet

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

M4, 115 bytes

Also TIL that ifelse can have more than four arguments.

define(f,`ifelse($1,101,,`ifelse(eval($1%15),0,fizzbuzz,eval($1%5),0,buzz,eval($1%3),0,fizz,$1)
f(incr($1))')')f(1)

Try it online!


M4, 143 bytes, SUSv2-compatible.

define(f,`ifelse(`$1',101,,`g(`$1',ifelse(eval($1%3),0,fizz)`'ifelse(eval($1%5),0,buzz))
f(incr($1))')')define(g,`ifelse(len($2),0,$1,$2)')f(1)

Try it online!

I am not familiar with M4, but I tried some bests. What quotations can be removed?

With comments

dnl def f(n): return "" if n==101 else g(n,("fizz" if n%3==0 else "")+("buzz" if n%5==0 else "")+"\n"+f(n+1))
define(f,`ifelse(`$1',101,`',`g(`$1',ifelse(eval($1%3),0,fizz)`'ifelse(eval($1%5),0,buzz))
f(incr($1))')')dnl
dnl def g(n,s): return n if len(s)==0 else n
define(g,`ifelse(len($2),0,$1,$2)')dnl
f(1)
\$\endgroup\$
1
\$\begingroup\$

Pinecone, 90 bytes

i:1|i<101|i:i+1@(i%3+i%5=0?print:"FizzBuzz"|i%3=0?print:"Fizz"|i%5=0?print:"Buzz"|print:i)
\$\endgroup\$
1
\$\begingroup\$

BRASCA, 58 bytes

1Hr,[0a:3%0=[a0`zziF`[o]]x:5%0=[a0`zzuB`[o]]A$=[x:n0]xxlo]

Try it online!

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

Knight, 50 48 43 bytes

;=n 0W>101=n+1nO|+*"Fizz"!%n 3*"Buzz"!%n 5n

Try it online!

-2 bytes: use string multiplication instead of IF

-5 bytes: I completely overlooked |, I assumed it had C semantics.

Ungolfed:

# start with n at 0
; = n 0
# increment n and loop while less than 101
: WHILE > 101 (= n + 1 n)
    # outlined from the output for clarity
    # concatenate:
    ; = fizzbuzz +
        # Fizz if n % 3 == 0
        : * "Fizz" ! (% n 3)
        # Buzz if n % 5 == 0
        : * "Buzz" ! (% n 5)
    # If fizzbuzz is not empty, output it, otherwise output n
    : OUTPUT | fizzbuzz n
\$\endgroup\$
1
\$\begingroup\$

C++20, 202 bytes

this is uncompetitive, but this was so fun I couldn't help but post it here.

#include <bits/stdc++.h>
using namespace std;auto f=[](int i){return i%15?(i%5?(i%3?to_string(i):"Fizz"):"Buzz"):"FizzBuzz";};int main(){for(auto i:views::iota(1,100)|views::transform(f))cout<<i<<endl;}
\$\endgroup\$
2
  • 1
    \$\begingroup\$ you have an extra space in 1, 100 \$\endgroup\$
    – hyperneutrino
    Commented Jul 14, 2021 at 3:19
  • \$\begingroup\$ @hyper-neutrino oh darn thanks \$\endgroup\$ Commented Jul 14, 2021 at 3:23
1
\$\begingroup\$

PostScript, 73 bytes

Using binary encoding:

000000 31 88 01 88 64 7b 2f 69 92 3e 92 33 28 46 69 7a
000010 7a 42 75 7a 7a 29 69 88 0f 28 42 75 7a 7a 29 69
000020 20 35 28 46 69 7a 7a 29 69 88 03 33 7b 92 6a 30
000030 92 3d 7b 2f 69 92 3e 92 33 7d 7b 92 75 7d 92 55
000040 7d 92 83 69 20 3d 7d 92 48

Try it online! (thanks to tail spark rabbit ear, ignore TIO's character count).

This is a straight-forward encoding of the following 101 byte program (in binary encoding, 136 n is a signed 8-bit integer and 146 n is command n from the system name encoding list in appendix F of the PostScript language reference).

1 1 100{/i exch def(FizzBuzz)i 15(Buzz)i 5(Fizz)i 3 3{mod 0 eq{/i exch def}{pop}ifelse}repeat i =}for

Try it online!

The non-binary encoded version can be reduced to 98 bytes if we don't mind leaving /i on the stack.

/i 1 1 100{def(FizzBuzz)i 15(Buzz)i 5(Fizz)i 3 3{mod 0 eq{/i exch def}{pop}ifelse}repeat i =/i}for

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I made you a TIO thing of the binary. \$\endgroup\$
    – user100411
    Commented Aug 8, 2021 at 9:16
  • 1
    \$\begingroup\$ @tailsparkrabbitear: Thanks for that. I hadn't even considered that the TIO bash would include Ghostscript. Perhaps put a note on the Postscript Code Golf tips page. \$\endgroup\$ Commented Aug 8, 2021 at 12:22
1
\$\begingroup\$

jq, 98 82 bytes

range(1;101)|if.%15<1then"FizzBuzz"elif.%3<1then"Fizz"elif.%5<1then"Buzz"else. end

Try it online!

Yet to golf it!

Removed superfluous spaces thanks to @DLosc.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Some simple golfs get you down to 82 bytes \$\endgroup\$
    – DLosc
    Commented Sep 4, 2021 at 4:00
  • \$\begingroup\$ Thanks @DLosc, I didn't realize you could remove the spaces! \$\endgroup\$
    – AviFS
    Commented Sep 4, 2021 at 4:31
1
\$\begingroup\$

RickRoll-Lang, 185 bytes

takemetourheart
give a up [*range(1,101)[::-1]]
togetherforeverandnevertopart
give i up a.pop()
give s up "Fizz"*(i%3<1)+"Buzz"*(i%5<1)
ijustwannatelluhowimfeeling [str(i),s][s>""]+"\n"

Explanation:

RickRoll-Lang keywords do not need spaces between them

takemetourheart                                   -- main() function declaration
give a up [*range(1,101)[::-1]]                   -- set a to reverse of int range [1, 101)
togetherforeverandnevertopart                     -- infinite loop
give i up a.pop()                                 -- pop last element of a and store in i
give s up "Fizz"*(i%3<1)+"Buzz"*(i%5<1)           -- string multiplcation to form fizzbuzz depending on modulus remainders
ijustwannatelluhowimfeeling [str(i),s][s>""]+"\n" -- print i if s is empty else s and a newline
                                                  -- implicit "say goodbye" (end block) at the end
                                                  -- another say goodbye

Try it online!

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

jq, 78 bytes

range(1;101)|. as $n|[(select(.%3==0)|"Fizz"),(select(.%5==0)|"Buzz")]|add//$n
\$\endgroup\$
1
\$\begingroup\$

Kotlin, 117 bytes

{for(i in 1..100){println("${if(i%3<1)"fizz" else ""}${if(i%5<1)"buzz" else ""}${if(!(i%3<1||i%5<1))"$i" else ""}")}}

Try it online!

as usual as it gets

edit: i hope the extra \n at the end is not a problem

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

Raku, 44 bytes

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

Try it online!

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

SQLite, 183 bytes

WITH F AS(SELECT 1 AS N UNION ALL SELECT N+1 FROM F WHERE N<100)SELECT CASE WHEN N%15=0 THEN'FizzBuzz'WHEN N%5=0 THEN'Buzz'WHEN N%3=0 THEN'Fizz'ELSE CAST(N AS VARCHAR)END AS F FROM F;

Try it online!

Ungolfed code:
WITH F AS(
  SELECT 
    1 AS N 
  UNION ALL 
  SELECT 
    N + 1 
  FROM 
    F 
  WHERE 
    N < 100
) 
SELECT 
  CASE WHEN N % 15 = 0 THEN 'FizzBuzz' WHEN N % 5 = 0 THEN 'Buzz' WHEN N % 3 = 0 THEN 'Fizz' ELSE CAST(N AS VARCHAR) END AS F 
FROM 
  F;
\$\endgroup\$
1
\$\begingroup\$

Squirrel, 131 bytes

for(local i=0;i++<100;)if(i%15==0)print("FizzBuzz\n")else if(i%5==0)print("Buzz\n")else if(i%3==0)print("Fizz\n")else print(i+"\n")

Try it online!

This is the original code that I created:

function fizzBuzz(n) {
  for (local i = 1; i <= n; i += 1) {
    if (i % 15 == 0)
      print ("FizzBuzz\n")
    else if (i % 5 == 0)
      print ("Buzz\n")
    else if (i % 3 == 0)
      print ("Fizz\n")
    else {
      print (i + "\n")
    }
  }
}

fizzBuzz(100);
\$\endgroup\$
1
\$\begingroup\$

Pascal, 162 B

See also Free Pascal. This program, however, requires a processor supporting features of ISO standard 10206 “Extended Pascal”, specifically the :0 width specifier in conjunction with string/char values. Usually, for numeric arguments the n in write(42:n) specifies a minimum width the decimal representation shall occupy. With string values, however, it specifies the exact width, i. e. possibly zero.

program p(output);var i:1..100;begin for i:=1 to 100 do if 0 in[i mod 3,i mod 5]then writeLn('Fizz':4*ord(i mod 3=0),'Buzz':4*ord(i mod 5=0))else writeLn(i:1)end.

For sake of readability the ungolfed version of above code plus some explanatory comments:

program fizzBuzz(output);
    var
        i: integer;
    begin
        { Remember, in Pascal `for`-loop limits are inclusive. }
        for i := 1 to 100 do
        begin
            { Create a `set of integer` and check membership of `0`: }
            if 0 in [i mod 3, i mod 5] then
            begin
                writeLn('Fizz':4 * ord(i mod 3 = 0), 'Buzz':4 * ord(i mod 5 = 0))
            end
            else
            begin
                { For numeric values `:0` would have the same effect as `:1`. }
                { Therefore this is in the `else` branch. }
                writeLn(i:1)
                { The `:1` just ensures there are no leading blanks }
                { regardless of implementation (the compiler) used. }
            end
        end
    end.

For a non-golfed version visit, for example, RosettaCode.

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

Phooey, 53 4847 bytes

[100+1@@@@%3{"Fizz">&<}&%5{"Buzz">&<}>{&$i}"
"]

Try it online!

Outgolfed the creator at his own language. 😏


[100            while cell is not 100
   +1             increment cell
   @@@@           push four copies to the stack
   %3             set cell to cell mod 3
   {              if cell is not zero
     "Fizz"            print fizz
     >&<               pop value into the next cell to mark it
   }              endif
   &              pop original value from stack
   %5{"Buzz">&<}  repeat for buzz
   >              move to the next cell
   {              if neither fizz or buzz set the next cell
     &                 Pop to the cell
     $i                print number
   }              endif 
   "\n"         print newline
                  all paths popped the value to this cell, loop
]               end

The stack and tape are all filled with a lot of junk (as in ~200 numbers on the stack 100 items on the tape) and at the end since I don't consistently move the pointer or pop the same amount of times, but I don't care. 😏

I may make fun of the interpreter, but it is a pretty nice language.

  • -5 bytes: Use stack instead of tape, and don't restore the tape and stack
  • -1 byte: Simplify the logic to avoid the extra pop (in exchange for double the stack usage 😛).
\$\endgroup\$
1
\$\begingroup\$

Assembly (MIPS, SPIM), 202 bytes

main:add$7 1
li$2 4
la$4 F
rem$6 $7 3
bnez$6 n
syscall
n:rem$5 $7 5
bnez$5 o
or$4 5
syscall
j e
o:beqz$6 e
abs$4 $7
li$2 1
syscall
e:li$2 11
li$4 10
syscall
bne$7'd'main
j$ra
.data
F:.asciiz"Fizz""Buzz"

Try it online!

Explanation

This does a lot of SPIM abuse 😏

This assumes the following features of an empty program:

  • $a3/$7 is 0
  • .data is otherwise empty and therefore page-aligned (address of F is 0x10010000)
# initial SPIM state:
#   $a0 ($4): argc
#   $a1 ($5): argv
#   $a2 ($6): envp
#   $a3 ($7): 0
main:
    add     $a3, 1         # Increment accumultor (initially 0)
    li      $v0, 4         # v0 = PRINT STRING
    la      $a1, FizzBuzz  # a1 = "Fizz\0Buzz\0"
test_fizz:
    rem     $a2, $a3, 3    # a2 = acc % 3
    bnez    $a2, test_buzz # skip if not multiple of 3
fizz:
    syscall                # print("Fizz")
test_buzz:
    rem     $a1, $a3, 5    # a3 = acc % 5
    bnez    $a1, test_num  # skip if not multiple of 5
buzz:
    or      $a0, 5         # FizzBuzz is aligned, FizzBuzz | 5 == FizzBuzz + 5
    syscall                # print("Buzz")
    j       newline        # print newline
test_num:
    beqz    $a2, newline   # skip if acc % 3 == 0
num:
    abs     $a0, $a3       # abs is shorter than move for positive nums
    li      $v0, 1         # v0 = PRINT NUMBER
    syscall                # print(acc)
newline:
    li      $v0, 11        # v0 = PRINT CHARACTER
    li      $a0, '\n'      # a0 = '\n'
    syscall                # print('\n')
    bne     $a3, 100, main # Loop if not 100 (I use 'd' to avoid a space)
    j       $ra            # return

    .data
FizzBuzz:
    .asciiz "Fizz"         # 0x10010000 = "Fizz\0"
    .asciiz "Buzz"         # 0x10010005 = "Buzz\0"
\$\endgroup\$
1
\$\begingroup\$

Whitespace(v0.3 on ideone.com), 210 bytes

code visualized with replacing space,tab,newline to 's','t','n':

sssnnsssnssstntssssnsssststtstsstnsstttnnstnssstttstttststnssttstnnstntssnntstnsnstnstnsstnssststsnsnssnstnsstssntsstnttsnnnnnssnstssttnsnttsttnttssnsnssssttsssstntstttnsstnsssssttttstsnsnstnsstnsssssnnssssnntn

Show result on ideone

Notice: This code works fine on ideone.com, though, has a wrong result on tio.com because of a difference in behavior of "putc" with a large number ( > 255 ).
Show wrong result on tio.com

Without the rule "Nothing can be printed to STDERR", this code can be shortened to 207 bytes with omitting an "end"(nnn) instruction.

Here is the disassembled code ( created with my original tool ).

push +0(0b)   # 0000: ss-s-n
mark +0(0b)   # 0004: nss-s-n
push +1(1b)   # 0009: ss-st-n
add           # 0014: tsss
dup           # 0018: sns
push +361(9b)  # 0021: ss-ststtstsst-n
push -3(2b)   # 0034: ss-ttt-n
call null     # 0040: nst--n
push +1909(11b)  # 0044: ss-stttstttstst-n
push -5(3b)   # 0059: ss-ttst-n
call null     # 0066: nst--n
mul           # 0070: tssn
jzero -0(0b)  # 0074: nts-t-n
dup           # 0079: sns
puti          # 0082: tnst
mark -0(0b)   # 0086: nss-t-n
push +10(4b)  # 0091: ss-ststs-n
dup           # 0099: sns
dup           # 0102: sns
putc          # 0105: tnss
mul           # 0109: tssn
sub           # 0113: tsst
jneg +0(0b)   # 0117: ntt-s-n
end           # 0122: nnn
mark null     # 0125: nss--n
copy +3(2b)   # 0129: sts-stt-n
swap          # 0136: snt
mod           # 0139: tstt
jneg +0(1b)   # 0143: ntt-ss-n
dup           # 0149: sns
push +97(7b)  # 0152: ss-sttsssst-n
mod           # 0163: tstt
putc          # 0167: tnss
putc          # 0171: tnss
push +122(7b)  # 0175: ss-sttttsts-n
dup           # 0186: sns
putc          # 0189: tnss
putc          # 0193: tnss
push +0(0b)   # 0197: ss-s-n
mark +0(1b)   # 0201: nss-ss-n
ret           # 0207: ntn
\$\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.