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 2
3
4 5
15
7
\$\begingroup\$

Common Lisp, 103 101 96 93 84 bytes

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

Try it online!

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

-5 bytes - shorter version of handling i=0

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

-9 bytes - by ASCII-only

\$\endgroup\$
3
  • \$\begingroup\$ You can use ~[ instead of ~:[ and remove the (= ... 0) to reduce it to 84 bytes (with a bit of rearrangement). (not posting link because it would spoiler current code-golf.io best) \$\endgroup\$
    – ASCII-only
    Commented May 16, 2018 at 9:26
  • \$\begingroup\$ @ASCII-only Thank you for suggestion but it seems unobvious, how to do it. Without (=(mod i 5)0) I seem to need to handle residues of 1,2,3,4 separately (and similiarily for (=(mod i 3)0): 1 and 2). \$\endgroup\$
    – user65167
    Commented May 24, 2018 at 20:08
  • 1
    \$\begingroup\$ No... just use ~:; to add a default fallback: (dotimes(i 101)(format t"~v^~[Fizz~[Buzz~]~:;~[Buzz~:;~a~]~]<newline>"i(mod i 3)(mod i 5)i)) where <newline> is replaced with literal newline \$\endgroup\$
    – ASCII-only
    Commented May 24, 2018 at 23:33
7
\$\begingroup\$

BuzzFizz, 86 bytes

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

Try it online!

Explanation

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

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

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

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

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

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

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

Discussion

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

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

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

\$\endgroup\$
7
\$\begingroup\$

Whispers v2, 150 bytes

> 100
>> (1]
> "Fizz"
> "Buzz"
>> 3+4
> 0
>> Then 5 6 6 3 6 4 3 6 6 3 4 6 3 6 6
>> 7ⁿR
>> Each 8 2
>> L∨R
>> Each 10 9 2
>> Output L
>> Each 12 11

Try it online!

Maybe it could be improved, but programming in Whispers is driving me crazy. I'm starting to hear voices...whispering...in my head

Explanation

In Whispers, numbers in lines beginning with >> refer to line numbers. Here is what each line is computing:

> 100                                   1:100
>> (1]                                  2:[1,2,...,100]
> "Fizz"                                3:"Fizz"
> "Buzz"                                4:"Buzz"
>> 3+4                                  5:"FizzBuzz"
> 0                                     6:0
>> Then 5 6 6 3 6 4 3 6 6 3 4 6 3 6 6   7:["FizzBuzz",0,0,"Fizz",0,"Buzz","Fizz"...]
                                         (FizzBuzz without numbers for values 0 to 15)
>> 7ⁿR                                  8:Modular indexing function into the previous array
>> Each 8 2                             9:[0,0,"Fizz",0,"Buzz","Fizz",...]
                                         (FizzBuzz without numbers for values 1 to 100)
>> L∨R                                  10:OR function
>> Each 10 9 2                          11:Zip with OR the arrays in lines 9 and 2
                                         (Complete list of FizzBuzz values)
>> Output L                             12:Print function
>> Each 12 11                           13:Print each value in line 11
\$\endgroup\$
7
+500
\$\begingroup\$

sed 4.2.2 -r, 94 bytes

G
:
s/\n.?$/&0&1&2&3&4&5&6&7&8&9/m
t
s/\w.{8}/&Fizz /g
G
s/ *\w[05]|$/Buzz/2g
s/^0*\n*| .*//mg

Try it online

This is my old solution from anarchy golf, minus 5 backslashes gained by -r.

The loop generates 00 to 99 preceded by newlines. Next, we prepend Fizz to lines 03, 06, ... taking advantage of the fact that the entry points are all separated by 9 characters. Then we handle instances of Buzz by looking for suffix of 0 or 5, plus an empty line to stand in for 100, and skipping the first match 00. The last line cleans up the garbage on the ends of Fizz-but-not-Buzz lines along with leading 0s and the first two lines.

Note: The behavior of mixing 2 and g flags in s is unspecified by POSIX but well-defined in GNU sed.

sed 4.2.2 (no -r), 98 bytes (based on a solution by tails)

s/\S\?/ 123456789/
s//&1 &2 &3 &4 Buzz &6 &7 &8 &9 Buzz /g
s/\([1 ]\S* .\S* \)[0-9]*/\1Fizz/g
L0
d

Try it online

Using a quite different approach, this solution wins by 1 byte when -r is not used. Thanks to @tails for sharing this approach with me!

The first two lines generate 1 to 100 separated by spaces with suitable Buzz replacements, along with an extra residual space before 11. To match for Fizz replacements, special care is needed to skip Buzz in multiples of 15 without skipping Buzz in 3k + 1 spots. We can do this by starting the pattern with a space, except that this does not work for the very first match, so [1 ] is used instead. The . in line 3 compensates for the extra space before 11, which is masked in the final output by L0.

L is a GNU-specific line formatting command that was "considered a failed experiment" and removed in later versions of sed.

\$\endgroup\$
2
  • \$\begingroup\$ Very cool, both the solutions. This is the first time I'm learning of L, I've added it as a sed golfing tip codegolf.stackexchange.com/a/220951 \$\endgroup\$
    – user41805
    Commented Mar 20, 2021 at 10:02
  • \$\begingroup\$ tail's solution becomes 93 bytes using -rn. it's interesting that flags save the same number of bytes for both answers, despite how different they are \$\endgroup\$
    – guest4308
    Commented Jul 24 at 10:10
7
\$\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\$
7
\$\begingroup\$

Cubestack, 178 162 bytes

M R2 f' M' S S' y S S' y2 M R' M' R E M r M' E2 M r2 M' E' U M R M' D E S R' b' R2 b r U2 r U2 S' E2 S R' B r l r U2 r U2 S' E' L S S' u S S' y2 M R' M' R F2 b y'

Try it Online!

Final cube state:

enter image description here

Another fine addition to the collection of FizzBuzz I've written.

Explained

M R2 f' M' S S' y      # For each item in the range [0, 100)
S S' y2 M R' M' R      #   Push that item + 1 to the stack
E M r M' E2 M r2 M' E' #   Push the list [3, 5] to the stack
U                      #   Calculate [(item + 1) % 3, (item + 1) % 5]
M R M' D               #   and check if each of those results is equal to 0
E ... E2               #   Push the list ["Fizz", "Buzz"] to the stack
L S S' u               #   and multiply the strings with the modulo equality list. 
                       #   This implements the ("Fizz" * (item % 3 == 0)) + ("Buzz" * (item % 5 == 0)) 
                       #   I use in my other fizzbuzzes to concisely do the multiplicity check
S S' y2 M R' M' R      #   Push the item + 1 to the stack again. Needed because there's no DUP yet
F2 b                   #   Logically or that with the FizzBuzz string and print with a newline. 
                       #   If the item isn't divisible by 3 or 5, then the fizzbuzz string will be empty
                       #   meaning the logical or here will return the number. Otherwise it'll return whatever word is needed.
y'                     # End the loop
\$\endgroup\$
7
\$\begingroup\$

MediaWiki markup + WP templates, 142 bytes

{{for nowiki|<br>|<nowiki>{{If then show|{{#ifeq:{{mod|{{{1}}}|3}}|0|Fizz|}}{{#ifeq:{{mod|{{{1}}}|5}}|0|Buzz|}}|{{{1}}}}}</nowiki>|count=100}}

Explanation

This will only work on the English Wikipedia.

{{for nowiki <!-- Simple loop -->
|<br> <!-- seperator for each line -->
|<nowiki>{{If then show| <!-- main looping code, wrapped in <nowiki> tags to prevent processing except by {{for nowiki}} -->
{{#ifeq:{{mod|{{{1}}}|3}}|0|Fizz|}}{{#ifeq:{{mod|{{{1}}}|5}}|0|Buzz|}}|{{{1}}}}}</nowiki> <!-- {{{1}}} is substituted with the index -->
|count=100}}

{{For nowiki}}'s source

{{If then show}}'s source

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

Acc!!, 260 245 237 bytes

-15 bytes and another -8 bytes thanks to Mukundan314

Count i while 100-i {
i+1
Count f while i%3/2-f {
Write 70
Write 105
Write 122
Write 122
0
}
Count b while i%5/4-b {
Write 66
Write 117
Write 122
Write 122
0
}
Count d while _ {
Count z while _/10 {
Write 48+_/10
_%10
}
_*10
}
Write 10
}

Try it online!

Explanation

Once you know how Acc!! works, this is mostly pretty straightforward. (Crash course: Count while loops increment their variable from 0 as long as their condition is true. Write takes an ASCII code and outputs the corresponding character. Bare expressions like i+1 are assigned to the accumulator, _. Division is integer division.)

Our code iterates i from 0 through 99; thus, the number in question on each iteration is actually i+1. We set the accumulator to this value at the top of the loop.

If i%3 is 2 (i.e. i+1 is divisible by 3), we want to print Fizz.

  • Loop f with condition i%3/2-f; we enter the loop iff i%3/2 is nonzero.
  • Inside the loop, write Fizz and set the accumulator to 0.
  • The second time through, f is 1, making i%3/2-f 0 and breaking out of the loop.

If i%5 is 4 (i.e. i+1 is divisible by 5), we want to print Buzz. Same approach as above.

If we printed Fizz and/or Buzz, the accumulator is now 0; otherwise, it is a positive number that we need to output. The number will have either one or two digits, and its 1's digit will not be 0.

  • Loop d with condition _: the accumulator is not 0.
    • Loop z with condition _/10: the accumulator has a 10's digit.
      • Write the 10's digit.
      • Set the accumulator to _%10, discarding the 10's digit.
    • Set the accumulator to _*10, shifting the 1's digit to be the new 10's digit.
    • After two times through the d loop, the accumulator becomes 0 and we exit the loop.

Finally, write a newline.

\$\endgroup\$
15
  • \$\begingroup\$ Was able to get it to 241 bytes by combining the writes for the digits. I hadn't thought of this until you mentioned it. \$\endgroup\$ Commented Apr 16 at 2:52
  • \$\begingroup\$ @Mukundan314 Aha! I was, as usual, trying to be too fancy. :P (Edit) Wait, wow, that's seriously clever, promoting the 1s digit to be the new 10s digit! \$\endgroup\$
    – DLosc
    Commented Apr 16 at 2:56
  • \$\begingroup\$ _/10/10^z for the inner loop saves one more byte. \$\endgroup\$ Commented Apr 16 at 2:58
  • 1
    \$\begingroup\$ It can actually be _/10*0^z for one less than that. \$\endgroup\$
    – DLosc
    Commented Apr 16 at 3:00
  • \$\begingroup\$ 237 bytes \$\endgroup\$ Commented Apr 16 at 3:08
7
\$\begingroup\$

J, 46 bytes

New Version, thanks to Bolce Bussiere:

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

Old version (52 bytes):

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

Explanation

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

getlist {~ getindex

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

In

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

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

In

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

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

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

\$\endgroup\$
6
  • \$\begingroup\$ Using < instead of ~: saves a byte \$\endgroup\$ Commented Apr 6, 2019 at 16:42
  • 1
    \$\begingroup\$ And (;,>)Fizz`Buzz instead of 'Fizz'(,>@;;)'Buzz' saves another 5 \$\endgroup\$ Commented Apr 6, 2019 at 16:56
  • 1
    \$\begingroup\$ @BolceBussiere < instead of :~:? \$\endgroup\$
    – ASCII-only
    Commented Apr 8, 2019 at 4:17
  • \$\begingroup\$ @ASCII-only the first : belongs to the verb 0: that returns the constant 0. The verb ~: represents 'not equal' \$\endgroup\$ Commented Apr 9, 2019 at 17:29
  • \$\begingroup\$ Idk, using just constant 0 worked for me \$\endgroup\$
    – ASCII-only
    Commented Apr 9, 2019 at 23:02
6
\$\begingroup\$

Transact-SQL, 163 143 124 110 bytes

This requires SQL Server 2012+

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

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

Formatted and explained:

declare @ int=1                      --@ is a valid variable name
a:                                   --shorter than WHILE
    print iif(@%3*@%5>0, ltrim(@),   --ltrim is shorter than explicit cast
          iif(@%3=0,'Fizz','')       --nest the IIFs
        + iif(@%5=0,'Buzz',''))
    set @+=1
IF @<101 GOTO a
\$\endgroup\$
12
  • \$\begingroup\$ Hello, and welcome to PPCG! Great answer! Can you please add an explanation? \$\endgroup\$ Commented May 6, 2016 at 2:06
  • \$\begingroup\$ Sure thing I'll include the ungolfed version, it's just a while loop \$\endgroup\$
    – Phrancis
    Commented May 6, 2016 at 2:06
  • \$\begingroup\$ I feel a bit privileged that in many languages you can't use expressions in case statements, but also a bit sad that the Oracle SQL person got fewer bytes... \$\endgroup\$
    – Phrancis
    Commented May 6, 2016 at 6:15
  • 1
    \$\begingroup\$ Good work, but this needs more golfing. Use GOTO, not WHILE. Skip CONCAT because you need to force only @ to be a string, so just enclose it in LTRIM or something. Use + for the Fizz and Buzz IIFs, and nest that in the IIF for the other numbers. Remove as many spaces as possible. I can get your entry down to 110 doing all that. \$\endgroup\$
    – Muqo
    Commented Jul 21, 2016 at 13:59
  • 1
    \$\begingroup\$ Code and explanation didn't match. Took the opportunity to edit in @Muqo's suggestions. \$\endgroup\$
    – BradC
    Commented Apr 19, 2018 at 17:32
6
\$\begingroup\$

rSNBATWPL, 57 bytes

for{i=1;i<101}$print{(("Fizz"*1>i%3)+"Buzz"*1>i%5)or++$i}

RSNBATWPL, or Radvylf Should Not Be Allowed To Write Programming Languages, is a "practical" programming language I've designed over the last week or so. It aims to be a sort of "super-JS/PHP/C++": a language that seems practical to the uninitiated and allows writing nice code, but deep down, is horribly cursed.

This is a significantly golfed version of my more readable FizzBuzz program:

n = cast.int{input{"Input: "}};

for {i = 1; i <= n; ++$i} {
    cond {(i % 3) and (i % 5)} {
        print{i};
    } {
        s = "";

        if {not{i % 3}} {
            s += "Fizz";
        };

        if {not{i % 5}} {
            s += "Buzz";
        };

        print{s};
    };
};

It uses a few interesting golfs, like replacing function calls (with {}) with the $ operator (which calls a function with an argument). It also relies on rSN's weird parsing order, with things like +"Buzz"*1>i%5 only being possible because rSN is always parsed right-to-left. In this case, we also make use of multiplying a string by a bool, a type hack similar to what you'd see in JS.

\$\endgroup\$
6
\$\begingroup\$

D, 90 bytes

import std;void main(){foreach(i;1..101)i.text.max("FizzBuzz"[i%3?4:0..i%5?4:8]).writeln;}

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to Code Golf, and nice answer! \$\endgroup\$
    – naffetS
    Commented Aug 19, 2022 at 15:45
6
\$\begingroup\$

Jellyfish, 124 105 98 97 92 87 64 50 bytes

P
LM`jr'e
1 B<1
 ^"FizzBuzz
 $ -*b373907863
 'dEE4

Try it online!
Try the 64B version online!
Try the 87B version online!
Try the 92B version online!
Try the 97B version online!
Try the 98B version online!
Try the 105B version online!
Try the 124B version online!

explanation

TBD

\$\endgroup\$
5
  • \$\begingroup\$ Heyo, welcome to code golf! This is quite a neat first answer, so keep up the good work! \$\endgroup\$
    – lyxal
    Commented Nov 16, 2022 at 10:41
  • \$\begingroup\$ Thx! I will add some code explanation after I prepare it. \$\endgroup\$
    – angel_p_57
    Commented Nov 16, 2022 at 11:13
  • 1
    \$\begingroup\$ i'm afraid 92 byte version is not working on TIO because of handling null input \$\endgroup\$ Commented Nov 26, 2022 at 10:00
  • 1
    \$\begingroup\$ Thank you for letting me know about the old sample on TIO was not working. I fixed it and update this post. \$\endgroup\$
    – angel_p_57
    Commented Nov 26, 2022 at 13:31
  • 2
    \$\begingroup\$ I misunderstood the "header" area on TIO as for title or some comment, and added a string on it. That's why the code was not working. \$\endgroup\$
    – angel_p_57
    Commented Nov 26, 2022 at 13:37
5
\$\begingroup\$

Befunge-93, 82 81 bytes

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

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

Try it in this online interpreter.


Attempts that didn't work

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

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

Vertical rendition of the above

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

\$\endgroup\$
5
\$\begingroup\$

SQL (PostgreSQL flavour), 107 bytes

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

Same sort of logic as my R answer

\$\endgroup\$
5
\$\begingroup\$

bc, 83 bytes

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

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

JavaScript, 79 bytes

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

Thanks to @ShadowCat we made it to 79 bytes:

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

Old solution, 87 bytes:

for(i=2,s="1";i<101;s+="\n"+["FizzBuzz","Buzz","Fizz",i][(i%3>0)+2*(i++%5>0)]);alert(s)
\$\endgroup\$
6
  • \$\begingroup\$ I recommend dropping the semi-colon at the end. Also I just used conditionals i%5?i%3?i:'Fizz':i%3?'Buzz':'FizzBuzz' and I got 79 bytes, so I recommend trying that. I would also avoid s="1" and just start i=1,s="" to save an extra byte \$\endgroup\$
    – ShadowCat7
    Commented Sep 24, 2015 at 20:44
  • 1
    \$\begingroup\$ I was working on a ?: solution but I was not able to get it to work before you commented=) Thank you very much! (Honestly I am still proud of my array indexing solution=P) \$\endgroup\$
    – flawr
    Commented Sep 24, 2015 at 20:50
  • \$\begingroup\$ A trailing newline is acceptable, but a leading newline is not. I don't like this rule, but it's a rule nevertheless \$\endgroup\$
    – edc65
    Commented Sep 24, 2015 at 21:16
  • \$\begingroup\$ 77: change starting part i=s="". 76 using ES6 and template string for newline \$\endgroup\$
    – edc65
    Commented Sep 24, 2015 at 21:42
  • \$\begingroup\$ 75: i recomment this for(i=0,s="";i++<100;s+=((i%3?'':'Fizz')+(i%5?'':'Buzz')||i)+"\n");alert(s), because it saves 6 \$\endgroup\$ Commented Sep 29, 2015 at 12:00
5
\$\begingroup\$

Haskell, 105 97 bytes

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

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

\$\endgroup\$
4
  • \$\begingroup\$ first line could be main=mapM(print . f)[1..100] \$\endgroup\$
    – wlad
    Commented Sep 25, 2015 at 11:34
  • \$\begingroup\$ You can write all the guards of f in a single line: f n|n%15="FizzBuzz"|n%3="Fizz"|n%5="Buzz". \$\endgroup\$
    – nimi
    Commented Sep 25, 2015 at 15:21
  • \$\begingroup\$ I count 96 bytes. If you write f 3++f 5 instead of "FizzBuzz", you can save two more. Also, henkma on anarchy golf has 82 somehow. \$\endgroup\$
    – lynn
    Commented Sep 26, 2015 at 22:12
  • 1
    \$\begingroup\$ I posted an 85 byte answer. \$\endgroup\$
    – lynn
    Commented Sep 27, 2015 at 14:45
5
\$\begingroup\$

Fortran, 213 bytes

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

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

\$\endgroup\$
1
  • \$\begingroup\$ Could possibly save bytes by setting a variable and writing it out once at the end, instead of multiple write statements. \$\endgroup\$
    – roblogic
    Commented Jun 30, 2021 at 23:59
5
\$\begingroup\$

MATLAB, 94 bytes

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

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

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

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


Old code:

MATLAB, 118 bytes

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

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

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

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


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

\$\endgroup\$
3
  • \$\begingroup\$ I like your solution! Just some hints, you can use [s,''] instead of char(s) (I'd add that in the disp.) Then if you have arguments like UniformOutput it usually suffices to just write U or Un (just as many letters needed for discerning the different possible arguments) and instead of true,false you can use 1,0 (or for true any finite value bigger but zero). This also means instead of s~=0 you can use ~s or if this does not work s>0 or s<0 depending on the application. \$\endgroup\$
    – flawr
    Commented Sep 25, 2015 at 22:50
  • \$\begingroup\$ @flawr Thanks for the tips. I hadn't realised that appending '' converted to a char string. I've saved 4 more bytes. Added the '' to the s=[ ] bit as it does the same as adding it in disp() but without the cost of the extra []. Also the s>0 was a bit of a duh moment on my part! \$\endgroup\$ Commented Sep 26, 2015 at 4:29
  • \$\begingroup\$ There is a Tipps for golfing in Matlab (and linked there one for golfing in Octave) might be worth reading (and expanding=). Happy golfing=) \$\endgroup\$
    – flawr
    Commented Sep 26, 2015 at 10:04
5
\$\begingroup\$

TI-BASIC, 59 bytes

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

Or at the same length:

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

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

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

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

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

  • TI-BASIC needs two bytes to encode every lowercase letter other than i (which represents the imaginary unit).
  • Empty strings are not supported: sub("FizzBuzz",5,0 and ""+"Buzz" both throw errors.
\$\endgroup\$
4
  • \$\begingroup\$ Wouldn't moving X to the 2nd to last line shave a byte? (Disp X?) (For the seond one) \$\endgroup\$ Commented Sep 29, 2015 at 0:08
  • \$\begingroup\$ Here are my suggested revisions (I don't have my calculator handy, so I'm not sure if it remains the same.) \$\endgroup\$ Commented Sep 29, 2015 at 0:49
  • \$\begingroup\$ Ohhhh I see. The Ans functionality sometimes confuses me. Sorry if I sounded pretentious ;) \$\endgroup\$ Commented Sep 29, 2015 at 0:53
  • \$\begingroup\$ I found a byte on the "naive" solution by storing "Buzz" to Str2 then "Fizz" to Str1 at the beginning of the loop, leaving "Fizz in Ans so lines 5 and 6 can use Str2 and Str1+Str2. Also by my byte counts following token size here: tibasicdev.wikidot.com/one-byte-tokens The naive solution is 70 bytes to the above 69. Between the optimal solutions, the one that does not precompute int(ln( on gcd(X,15 should be the smallest at 60 bytes to 61 for the other. \$\endgroup\$
    – TiKevin83
    Commented Nov 22, 2019 at 16:34
5
\$\begingroup\$

Groovy, 69 Bytes

(1..100).each{i->println i%15?(i%5?(i%3?i:'Fizz'):'Buzz'):'FizzBuzz'}
\$\endgroup\$
1
  • 3
    \$\begingroup\$ Can save 2 bytes using 1.upto(100){} and no parenthesis are needed in your answer, resulting in: 1.upto(100){i->println i%15?i%5?i%3?i:'Fizz':'Buzz':'FizzBuzz'}​ +1 though :). \$\endgroup\$ Commented Oct 13, 2016 at 17:49
5
\$\begingroup\$

APL, 41 bytes

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

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

\$\endgroup\$
6
  • \$\begingroup\$ Do you need the space between ' and ? \$\endgroup\$
    – Adalynn
    Commented Aug 3, 2017 at 20:34
  • \$\begingroup\$ Oh, I haven't used GNU APL in a while, is the needed, since you display directly to STDOUT? \$\endgroup\$
    – Adalynn
    Commented Aug 4, 2017 at 22:15
  • \$\begingroup\$ @Zacharý In GNU-APL monadic 'left tack' discards the value of the right argument. I read it as return nothing (since it points to left). I hope this is the correct way to phrase it. on the other hand, I do not have experience with Dyalog or a ready-setup to play with. \$\endgroup\$ Commented Aug 6, 2017 at 18:45
  • \$\begingroup\$ Oh, for some reason I was thinking the return value was not written to STDOUT by default. \$\endgroup\$
    – Adalynn
    Commented Aug 6, 2017 at 19:05
  • \$\begingroup\$ It's not in Dyalog, but it is in GNU. \$\endgroup\$
    – Mark Reed
    Commented Feb 22, 2023 at 2:20
5
\$\begingroup\$

MathGolf, 24 22 bytes

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

Try it online!

Explanation

♀                         Push 100
 {                        Start block
  î                       Push loop counter (1-indexed)
   ╕Σ╠δ                   Decompress "Σ╠" and capitalize to get "Fizz"
       ╕┌╠δ               Decompress "┌╠" and capitalize to get "Buzz"
           `              Duplicate top 2 elements of stack
            +             Add (creating "fizzbuzz")
             Γ            Wrap top 4 elements of stack in array
              î           Push loop counter (1-indexed)
               3          Push 3
                5         Push 5
                 α        Wrap last 2 elements in array
                  ÷       Check divisibility (implicit mapping)
                   ä      Convert from binary to int
                    §     Get array item
                     p    print
                          End block on code end, for loop implicit (100 iterations)
\$\endgroup\$
2
  • \$\begingroup\$ @dzaima Darn, I forgot about that completely. I have however had a capitalization operator in mind for a while. That should add one byte to the solution, but it is not yet implemented. \$\endgroup\$
    – maxb
    Commented Sep 12, 2018 at 19:33
  • \$\begingroup\$ I fixed the capitalization, at the cost of two bytes. \$\endgroup\$
    – maxb
    Commented Sep 13, 2018 at 6:58
5
\$\begingroup\$

brainfuck, 628 499 bytes

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

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

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

Any feedback or shrinkings are appreciated!

Badly commented source code

Try it online!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Some quick golfing; There's some leftover whitespace in the code, and all the [-]s can be replaced with ,s (if you're okay with EOF being 0). At least one of the [-]s isn't necessary. The not of the modulo will probably be shorter with forking the movement instead ([>>]<), making sure the tape ends up the same afterwards \$\endgroup\$
    – Jo King
    Commented Feb 28, 2019 at 2:26
  • 1
    \$\begingroup\$ I don't think any of my implementations support EOF as 0, but I am interested in the unnecessary [-] clear cell and the [>>]<. Is there a chance you can suggest an edit? \$\endgroup\$ Commented Feb 28, 2019 at 5:35
  • \$\begingroup\$ 596 bytes without whitespace and redundant [-]s. I think you'll find that most implementations use 0 as the EOF, and even the ones that don't usually use -1/255, which is still one byte shorter. I guess there's also no change, but that's rare. I'll work on the [>>]< part \$\endgroup\$
    – Jo King
    Commented Feb 28, 2019 at 6:11
  • \$\begingroup\$ 499 bytes. I've changed it to the [>>]< method I mentioned above, and golfed some other parts. I didn't really touch the print as a number part, so you can probably golf something there. \$\endgroup\$
    – Jo King
    Commented Feb 28, 2019 at 8:02
5
\$\begingroup\$

SQL (Oracle), 112 108 bytes

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

db<>fiddle here

\$\endgroup\$
1
  • 2
    \$\begingroup\$ ''||LEVEL can be simple replaced with level \$\endgroup\$
    – Dr Y Wit
    Commented Aug 28, 2019 at 14:15
5
\$\begingroup\$

Seed, 6015 bytes

186 83944644497775792185807323999861330742900673481712359255839929374667216476568023851764637813248013688693896717275687232066153870107749175160194707761486575005885313952906442913325967953944535811512056079183251514390746052490451307246213606447865255212286265116943188690839445165359981774554198082946825007384980162551436390435260155582466874315352220541140434954811560506556477075852586817070090764184077321583489797358147025926992986354865415277367374043398355163643621296927936732212800075642321038031920620549375319366961667358107695950468557182519902148699776620624078332688843597417318685229781090303723160175745852091928346724348001020777912570918121340035523698691520422590527296248455779012094897281946771732844646467975422651655880202725095981882371807518829844157636552230152953535332201239998966830698645115246907049972204010095894629001206397276344975636564553238199728981112245810583644580269593382612869323054013019350314231784293448249910440692956496060253971880373279161390518237118507378691330341470412624728172421405109963475552981299919837091765136501358887135317778357279769289706821629750840213676581513947891276551415821187603189444230553630205086966993211879390093045277089486589385876312541940492767981701353769007246001400130719416118275492304807198011860072050303044225722194337717896831470037434122578382321765362062455130027125953869723625862069785410531287781468150359623495258126317807476517184801674197008747267394632928708383370640309530427431150403028006421518064783676469959724647961395869176187323826585310379142853088186864023708457159764123364029018721951815248751431170413579315400528983481702298849209797951129827235189965388114007169146563257209800975334610910397591190300324319540160364733177122449656422045835924029442449258975425381755648345550014417207471617919736685787448764321614059138375253980386335770138273578332418379763049794151811098188219754733324389355566317376598492318359989945589480418455750455469859956801589082779968271578522034926104268403877968397758570110853038536860556853388613997493905742068279137736678857073233174739380697685907170886092925173057794582407478105690770633669349947638020604803238951194381273510993928897230197983256465537488284258216944902276278712201715008765995404107536372438956009631805114079400698265046614085687812688769068889878215788959245601084883372435344000194364054441952170474833494604130017222942459218768152451353838900515646024764453476453552863938005162079649698291854043301771100462916706520075039044805956181705047266329114921035274711980897862579454154525144505597823262540025190878917613039796282312555295659294071407630514652646787462515667390800389392114746442068094785615537685660298361617697365653764669207754605147347324074541222276275532258194690926246437097055706104108319469003781845674958634242078791475826910418111428349167152839025683587469305219626924263962611094845308744968793376752461012553325189830937237777556407663277494722334379175044299145527685100424059993166500276116324651034389342857099326382267792125696063602436504279969923412378117936327869017861642388185619118723658181098871790872093500520584752433465443515989483851486224923341213990357424279098636563794743080022540640677640107176034203326304825856510242291526956869439836743210321616337131260522898066320086593786007891762080406650341513081903510025534886914361255147039463158189995500627220823997958074917925862170348467342212390436963261050291735696261617106196786273505443408966191019872244618002281427523777003325474230066462489531195157755555344637353155356279454281010364750875012491070816465270498678197434494849001514802132418781410405222031814823702582955264273367316636558580379660009282902598817700470535664545017234816209988594892835104965686956867851308392004044845547855039571721575449154495443479356960829759209226823917197487855397504141411230632224369201022681688301238065753737278463677847356448662974398206270856674118500884955014781944009536761710654880983265123955150729759406311220705702903728217724237231225228243114081826682040349685205121446193821261139703572900811243143912445467975694459999888915923116875430564637390061881889161512304819029656014338113772447267072899546161543780769850725712979853265124144813517511575434597175140160445249538753447856073028845070404104820699013418827593400549228758486817648053770622330987136941236768786640613654490823959024174575959620155957372041756651311988259843620347948677131103848960623371212015137053539005334518693964703094514744873758157905983139622925587291886231049371800498250086745691716656644176053612172113439907334397406577774498757112425437339205922869531575921611548158798375762386782843394828401126984185115349224303420458491251207091698634206841378497320259972637725826224808114267917428717816623368840721796784587349258491132128347823644310226457190477267965710821892576687103122134712656694901146343938508484308662925632874468476850854977933467327214644382364732022885458172449643330918925157997124690072012401561398600599725096512808715148150880033416494352767432615596760722206416684175988533830899565642405659319720681197534141300323187308210290375660950200938389996580887564670049743784962037885099514826194024014058093062057706139814777110125812527054724707373942053107785831307633110641398607263726549612409340127167852023607787965086360296071952107945138419803900924977980375619565210182772121849111987355981226968062629667279278470647719759267716675652568099185449478479471691254158308189631416224208590609150412906273490206303890853713104183863050119383440553687111132467944761189779633340481533657859382354192428154204487886313458547651002779223927726608436086877353829832057341247094095114657693381028772025327489391112902949559367893876211447144802835381133403893955836438518252858893637260806405255643702579004661210305919494653119109150790218729956868835489222681506976514342204634574313468575534020458319909578144280137077342941741913678288702984697189445809519253013406175446129538246339672293879388869701830984873958965248

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Oh, my generator must have glitched. I'll look on this \$\endgroup\$ Commented Sep 8, 2019 at 11:46
  • \$\begingroup\$ @JoKing Well, I should have tested my stuff before. Now it works \$\endgroup\$ Commented Sep 8, 2019 at 12:25
5
\$\begingroup\$

Arn -hm, 27 22 18 bytes

─=█BƒHXåõÝü»ÝÑÕ=!&

Try it!

Explained

Unpacked: "Fizz"^!%3|`#&`^!%5||

Set STDIN to the range [1, 100]

      "Fizz" Literal string
    ^ Repeat
      ! NOT
          _ Implied variable
        % Modulo
          3
  | Concatenated with
      `#&` Compressed string "Buzz"
    ^
      !
          _ Implied
        %
          5
|| OR
  _ Implied

Mapped over STDIN with key`_

I wasn't going to update this, but might as well.

\$\endgroup\$
5
+400
\$\begingroup\$

GNU sed 4.2.2, 126 bytes

This answer is in response to the bounty offered by @user41805 to golf further his sed script for this challenge.

s/^/@@,/;h
:
y/@123456789';,/123456789@;,'/
/@.$/!{x;G;s/..\n.//}
h
s/[@5].$/&Buzz/
s/.*,/Fizz/
s/.*\WB/B/
s/\W*//gp
g;/@@/d
t

Try it online!

The trick was to notice that no '0' will be printed, so I replaced it with '@' to be able at line 9 to refer to the extra characters [0';] as \W, thus shaving 3 bytes. Please check his description on how the code works.

\$\endgroup\$
5
\$\begingroup\$

Pip, 32 31 30 bytes

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

Attempt this online!

Here's the 31-byte equivalent in Pip Classic: Try it online!

Explanation

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

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.