173
\$\begingroup\$

Introduction

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

Challenge

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

Output

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

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

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

Further Rules

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

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

  • Nothing can be printed to STDERR.

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

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

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

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

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

  • Standard loopholes are otherwise disallowed.

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

Catalogue

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

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

343 Answers 343

1
5 6
7
8 9
12
2
\$\begingroup\$

C#, 119 bytes

class q{static void Main(){for(var i=0;i++<100;)System.Console.WriteLine(i%3*i%5>0?i+"":$"{i%3:;;Fizz}{i%5:;;Buzz}");}}

Try it online!


I was wondering how close I could get to the long standing 124 byte C# answer by Pierre-Luc, so I challenged myself to try. After unexpectedly beating it by just one byte (123 bytes, Try it online!), I took the advice from @LiamK's three year old comment and used string interpolation to shave off another 4 bytes. I'm genuinely surprised by how well this worked out!

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

K (oK), 49 46 43 bytes

Solution:

`0:{$[a:,/$&`Fizz`Buzz!~5 3!'x;a;x]}'1+!100

Try it online!

Explanation:

`0:{$[a:,/$&`Fizz`Buzz!~5 3!'x;a;x]}'1+!100 / the solution
                                       !100 / range 0..99
                                     1+     / add 1
   {                               }'       / apply lambda {} to each number
    $[                        ; ; ]         / conditional, $[if;then;else] 
                        5 3!'x              / apply modulo (!) of each 5 and 3 to the input x
                       ~                    / not (0->1, anything else->0)
            `Fizz`Buzz!                     / turn results into a dictionary
           &                                / keys where true
          $                                 / convert to strings
        ,/                                  / flatten
      a:                                    / save as a
                               a            / result if a is not empty - so Fizz / Buzz
                                 x          / result if a is empty - so 1, 2, 4
`0:                                         / print to stdout

Notes:

  • -6 bytes thanks to @ngn with a new approach
\$\endgroup\$
4
  • 1
    \$\begingroup\$ 2 2/ -> 2/­­­­, @' -> ' \$\endgroup\$ – ngn Oct 1 '18 at 3:48
  • \$\begingroup\$ it produces the same output without the $ \$\endgroup\$ – ngn Oct 2 '18 at 13:13
  • \$\begingroup\$ `Fizz`Buzz`FizzBuzz -> a,,,/$a:`Fizz`Buzz \$\endgroup\$ – ngn Oct 2 '18 at 13:18
  • 1
    \$\begingroup\$ and here's a slightly shorter one abusing "where" on dicts: `0:{$[a:,/$&`Fizz`Buzz!~5 3!'x;a;x]}'1+!100 \$\endgroup\$ – ngn Oct 2 '18 at 13:37
2
\$\begingroup\$

Brachylog, 48 bytes

100⟦₁{f{∋15∧"FizzBuzz"|∋3∧"Fizz"|∋5∧"Buzz"|t}ẉ}ᵐ

Try it online!

Probably not golfed too well but it works.

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

Java 8, 129 bytes

interface I{static void main(String[]s){for(int i=0;++i<101;)System.out.println(i%15<1?"FizzBuzz":i%3<1?"Fizz":i%5<1?"Buzz":i);}}

Try it online

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

Scheme, 118 bytes

(for-each(lambda(i)(printf"~a~a~%"(if(=(mod i 3)0)'Fizz"")(if(=(mod i 5)0)'Buzz(if(=(mod i 3)0)""i))))(cdr(iota 101)))

Try it online!

Ungolfed:

(for-each
 (lambda (i)
   (printf
    "~a~a~%"
    (if (= (mod i 3) 0) 'Fizz "")
    (if (= (mod i 5) 0) 'Buzz 
        ;; else
        (if (= (mod i 3) 0) "" i))))
 (cdr (iota 101)))
\$\endgroup\$
2
\$\begingroup\$

C, 98 94 bytes

i;main(){for(;++i<101;)i%3*i%5?printf("%d\n",i):printf("%s%s\n",i%3?"":"Fizz",i%5?"":"Buzz");}

Pretty simple stuff...

Thanks to Yoris Fresh for helping me save a couple bytes. Thanks to Jerry Jeremiah for pointing out a mistake in the ungolfed version.

Ungolfed:

i;
main() {
    for (; ++i < 101;)
        i % 3 && i % 5 ?
            printf("%d\n",i) :
            printf("%s%s\n", i % 3 ? "" : "Fizz", i % 5 ? "" : "Buzz");
}
\$\endgroup\$
1
  • \$\begingroup\$ the ungolfed version increments i twice each loop. \$\endgroup\$ – Jerry Jeremiah Jun 4 '19 at 3:33
2
\$\begingroup\$

05AB1E, 24 bytes

тÝ3Å€"Fizz"}5Å€á”ÒÖ”J}¦»

Try it online!

Explanation:

тÝ                  # range 0..100
  3Å€      }        # for every 3rd element...
     "Fizz"         # replace it with Fizz    
  5Å€      }        # for every 5th element...
     á              # keep only letters...
      ”ÒÖ”J         # and append "Buzz"
            ¦       # drop the first element
             »      # join with newlines
                    # implicit output

Or alternatively:

тÝ35vyÅ€á”FizzÒÖ”#NèJ]¦»

Try it online!

35vy iterates over the digits of 35, which avoids repeating Å€}. ”FizzÒÖ” is the string Fizz Buzz, and then #Nè selects the appropriate element.

Legacy 05AB1E doesn’t have Å€, so neither of those work for it. However, legacy à (set intersection) implicitly splits numbers, which lets us get a 26 that only works on legacy:

тLεDÑ35Ãvá”Fizz ÒÖ”#yèJ},

Try it online!

тLε                         # for y in 1..100
   DÑ                       # divisors of y
     35Ã                    # keep only those in [3, 5]
        v               }   # for each...
         á                  # keep only letters
          ”Fizz ÒÖ”#yèJ     # append either Fizz or Buzz
                         ,  # print with newline
\$\endgroup\$
0
2
\$\begingroup\$

Pip, 43 41 bytes

Fa1,101{i:0a%3?i:1O"FIZZ"a%5?i?PaPxP"BUZZ"}

Lh{i:0o%3?i:1O"FIZZ"o%5?i?PoPxP"BUZZ"++o}

Try it online!

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

Ink, 77 70 57 48 bytes

-(n){n%3:{n%5:{n}}|Fizz}{n%5: |Buzz}
{n<100:->n}

Try it online!

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

Julia, 87 bytes

z(i)=(f=i .%[3,5] .==0;sum(f)>0 ? foldl(*,["Fizz","Buzz"][f]) : i)
println.(z.(1:100))

Or we could kind of cheat to drop 3 bytes and use show instead of println. Julia 83 bytes

z(i)=(f=i .%[3,5] .==0;sum(f)>0 ? foldl(*,["Fizz","Buzz"][f]) : i)
show(z.(1:100))

or a more legible FP style, poor performing, 91 bytes

F(x)=foldl(*,["Fizz","Buzz"][x .%[3,5] .==0])
N(y)=F(y)=="" ? y : F(y)
println.(N.(1:100))

Julia isn't really made for this, but I had fun thinking about this a bit :).

\$\endgroup\$
5
  • \$\begingroup\$ prod is better than foldr(* \$\endgroup\$ – H.PWiz Nov 23 '19 at 23:45
  • \$\begingroup\$ Nice! I didn't think that'd work. Either way my solution is 10s of bytes away from the best Julia one :). \$\endgroup\$ – caseyk Nov 23 '19 at 23:51
  • \$\begingroup\$ Sure. My score is here \$\endgroup\$ – H.PWiz Nov 24 '19 at 12:25
  • \$\begingroup\$ Woah! How'd you do it? Or is that a secret? :) We have a thread that divulged into codegolf on julia discourse! \$\endgroup\$ – caseyk Nov 24 '19 at 13:10
  • \$\begingroup\$ Sort of a secret. Although I have discussed julia golfing in a chat room on this site. \$\endgroup\$ – H.PWiz Nov 24 '19 at 21:56
2
\$\begingroup\$

Python 3, 80 bytes

for x in range(1,101):print(("Fizz"if x%3==0else"")+("Buzz"if x%5==0else"")or x)
\$\endgroup\$
2
\$\begingroup\$

MC6000 ASM (Shenzhen I/O), 133 Bytes

add 1
mov acc x3
mov 51 x2
mov acc x2
mov 3 x2
teq x2 0
+mov 1 x1
mov 51 x2
mov acc x2
mov 5 x2
teq x2 0
+mov 2 x1
slp 1
mov -999 x1

Uses an MC4010 co-processor on x2, numeric display on x3, and a custom fizzbuzz display on x1.

"Hardware":

"Hardware" Configuration

Custom LCD:

enter image description here

Technically doesn't follow the rules as MCxxxx don't have a STDOUT, but I did the best I could.

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

APL, 52 chars/bytes

generate integers from 1 to n

b is a 2 by n boolean matrix highlighting multiples of 3 and 5

b←0=3 5∘.|⍵

c is a boolean vector highlighting multiples of either 3 or 5

c←∨⌿b

format each integer into a character vector

⍕¨⍵

where a number is a multiple of either 3 or 5...

@{c}

...put either Fizz or Buzz (i.e. discard the last 4, the first 4 or no character at all from the string "FizzBuzz" according to b)

(↓∘'FizzBuzz'¨¯4 4+.×c/b)

transform the nested vector into a matrix

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

sed 4.2.2, 129 bytes

A 400-rep bounty for those who outgolf this solution https://codegolf.meta.stackexchange.com/a/18428/

s/^/00,/;h
:
y/0123456789';,/1234567890;,'/
/0.$/!{x;G;s/..\n.//}
h
s/[05].$/&Buzz/
s/.*,/Fizz/
s/.*\WB/B/
s/[0';]*//gp
g;/00/d
t

Try it online!

s/^/00,/;h

Each number is stored as three characters, the first two store the two-digit padded decimal number, and the last character stores its modulo 3.

: ... t

In a loop,

y/0123456789';,/1234567890;,'/

the modulo is cycled, and the number is incremented using transliteration. Each digit is increased modulo 10, then

/0.$/!{x;G;s/..\n.//}

a simple conditional corrects the first digit on the number if necessary, using the fact each number is stored with exactly 3 characters.

h

This incremented form is stored in the hold space.

s/[05].$/&Buzz/

Buzzs are added by looking at the last base-10 digit of the number.

s/.*,/Fizz/

Fizzs are added by looking at the modulo-3.

s/.*\WB/B/

There is some cleanup of the number, remove the base-10 digits if needed and

s/[0';]*//gp

remove leading 0s and the modulo-3 so that it is print-ready, and print it.

g;/00/d

Finally retrieve the number from the hold space and exit if 00 is present, i.e. 100 has been reached

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

Rust, 114 bytes

It's not the shortest one available (on code-golf.io someone managed to somehow solve it in 99 bytes, but I have no idea how).

fn main(){(1..101).for_each(|i|println!("{}",["FizzBuzz","Fizz","Buzz",&i.to_string()][1.min(i%5)+2.min(i%3*2)]))}

First off, the obvious part

fn main() {/*..*/}

Then we iterate from 1 to 100 (inclusive) and println! an element of the array

(1..101).for_each(|i| println!("{}", ["FizzBuzz", "Fizz", "Buzz", &i.to_string()][/*..*/]))

To choose the right index, we use the following, where i is the current number

1.min(i % 5) + 2.min((i % 3) * 2)

The first part is 0 if i is a multiple of 5. Otherwise it's 1.

The second part is 0 if i is a multiple of 3. Otherwise it's 2.

Examples:

1.min(1 % 5) + 2.min((1 % 3) * 2) == 1 + 2 == 3 => "1"
1.min(3 % 5) + 2.min((3 % 3) * 2) == 1 + 0 == 1 => "Fizz"
1.min(4 % 5) + 2.min((4 % 3) * 2) == 1 + 2 == 3 => "4"
1.min(5 % 5) + 2.min((5 % 3) * 2) == 0 + 2 == 2 => "Buzz"
1.min(15 % 5) + 2.min((15 % 3) * 2) == 0 + 0 == 0 => "FizzBuzz"

This way, if both parts produce 0, we get the string FizzBuzz. If the sum is 1 we get Fizz, if it's 2 Buzz, if it's 3 we get &i.to_string() (the stringified number).

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can replace println! with print! and add a literal (as in press ENTER/RETURN) newline after the {} in the format string to save a byte. Also, if you're allowed to use a closure, it'd save quite a few bytes over using fn main(). Finally, you save some bytes using a for loop. 99 bytes: TIO \$\endgroup\$ – TehPers Aug 3 '20 at 22:15
2
\$\begingroup\$

Javascript 78 (but kinda 58) bytes

Produces the required string, then prints it. The function that produces the string is 58 bytes, another 20 are used to call console.log.

z=n=>n?z(n-1)+((n%3?'':'Fizz')+(n%5?'':'Buzz')||n)+'\n':'';console.log(z(100))

Javascript 72 71 bytes (thanks, Jo King!)

Prints the required lines as it goes. Interweaving console.log with the logic creates a shorter, though less elegant, program.

z=n=>n&&(z(n-1),console.log((n%3?'':'Fizz')+(n%5?'':'Buzz')||n));z(100)

It can also be written like the following, to the same effect and byte count.

z=n=>n&&console.log((z(n-1),(n%3?'':'fizz')+(n%5?'':'buzz')||n));z(100) 

De-golfed version:

z = n =>           // take n as argument
  n && (           // if n is not falsey (e.g. if it is not 0)
    z(n-1),        // use the comma operator to call the previous fizzbuzz
    console.log(   // then print a line
      (n%3 ? '' : 'Fizz')   // 'Fizz' if n is a multiple of 3, otherwise empty
      + (n%5 ? '' : 'Buzz') // Concatenated with 'Buzz' if multiple of 5
      || n         // Or just the number n if the previous string is empty, which implies that n is not divisible by 3 or 5
    )
  );
z(100)             // Run fizzbuzz from 100
\$\endgroup\$
1
  • \$\begingroup\$ You can save 5 bytes (on every solution) by using alert instead of console.log \$\endgroup\$ – VFDan May 19 '20 at 0:46
2
\$\begingroup\$

W d, 29 23 bytes

&ó╞╟↨5O╓46N☻»½_49ƒZÄ▬«Σ

A raw source is here.

After decompression:

2^                         E % Foreach in the 1..100 range
        a3m!                 % If the current item is divisible by 3:
  "Fizz"    *                % Return "Fizz"
             "Buzz"a5m!*     % If the current item | 3 -> "Buzz".
                        +    % Join those results
                         a|  % Logical OR this result with the current item
                              % Implicit print
\$\endgroup\$
2
\$\begingroup\$

Stax, 27 bytes

éeO├φ☻mRàzΦ╛`φ#2àáÿ²øΔ=L←§b

Run and debug it

Unpacked and Uncompressed

A2#F~;3%z"Fizz"?;5%z"Buzz"?+cz=,a?P
\$\endgroup\$
0
2
\$\begingroup\$

Keg, 58 40+4 43 bytes

1(d|0&:3%[|`Fizz`,⑹]:5%[|`Buzz`,⑹]&[|:.]
,⑨

Try it online!

-14 bytes thanks to @EdgyNerd and then -1 byte due to using register

Answer History

58 bytes

1(d|:\“%0=[`FizzBuzz`|:5%0=[`Buzz`|:3%0=[`Fizz`|:⅍]]],
,⑨)

Try it online!

String compression and string formatting are both useless here. Just a standard implementation of Fizzbuzz in Keg.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Idea to golf some bytes: couldn't you push an empty string, and then concatenate 'Fizz' if it's a multiple of 3, and then concat 'Buzz' if it's a multiple of 5, to save the FizzBuzz in your code (and probably some other bytes) \$\endgroup\$ – EdgyNerd Dec 1 '19 at 11:08
2
\$\begingroup\$

W n, 22 21 bytes

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

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

Uncompressed:

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

Explanation

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

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

International Phonetic Esoteric Language, 61 60 bytes

{2T}1ɑeb3ⱱɐbʌɔ|a|"Fizz"u|a|q5ⱱɐbʌɔ|b|"Buzz"u|b|ɞʌue1sø"\n"uɒ

Explanation:

{2T}1                                                        (push loop bounds 1 to 2T == 101 base36)
     ɑ                                                       (start loop)
      eb                                                     (push and dup loop index)
        3ⱱɐbʌɔ|a|"Fizz"u|a|                                  (print if fizzy)
                           q                                 (OVER)
                            5ⱱɐbʌɔ|b|"Buzz"u|b|              (print if buzzy)
                                               ɞʌu           (else print the number)
                                                  e1sø       (increment loop index)
                                                      "\n"u  (print a newline)
                                                           ɒ (end loop)

-1 byte for using base 36 for 101.

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

MAWP, 120 bytes

[!!3P3WA<75W2W;73W5W;65W2W1M2W;65W2W1M2W;~0~>%!!5P5WA<92M6W;94M9W;65W2W1M2W;65W2W1M2W;~0~>%~{~!:~}~!554WWA?.%1M25W;~(%)]

Try it!

Created this while testing my new online interpreter!

Explanation:

[                                              Start loop
!!3P3WA                                        Is divisible by 3? (Homemade modulo 
                                               function)
<                                              If top of stack is not 0 (number is
                                               not divisible), then jump to its >
75W2W;73W5W;65W2W1M2W;65W2W1M2W;               Print 'Fizz'
~0~                                            Add 0 to the bottom of stack by 
                                               double reversing
>                                              End conditional
%                                              Remove modulo function result
!!5P5WA<92M6W;94M9W;65W2W1M2W;65W2W1M2W;~0~>%  Do the same for 'Buzz'
~                                              Reverse stack
{                                              If there are no 0 on the top of 
                                               stack (not 'Fizz' nor 'Buzz' was
                                               printed), 
~!:~                                           then print the current number
}~                                             End conditional and reverse stack
!554WWA?.%                                     If the number is 100, then terminate
                                               program
1M25W;                                         Print newline
~(%)                                           Remove all 0 from bottom of stack
]                                              End of loop
\$\endgroup\$
2
\$\begingroup\$

Python 2, 73 77 bytes, link

edit:

Even shorter, thanks to @Dingus + removing parenthesis:

for n in range(1,101):print[[n,"Buzz"],["Fizz","FizzBuzz"]][n%3<1][n%5<1]

original:

Here's my matrix-inspired approach:

for n in range(1,101):
    print([[n,"Buzz"],["Fizz","FizzBuzz"]][n%3<1][n%5<1])

It avoids double checking modularity for 15. Written out a bit more elaborately, this becomes

for n in range(1,101):
    matrix=[[n     ,"Buzz"    ],
            ["Fizz","FizzBuzz"]]
    
    print(matrix[n%3==0][n%5==0]) # checking ==0 adds 1 byte versus <1.
\$\endgroup\$
2
  • \$\begingroup\$ Welcome to the site, and nice first answer! You might like to include a link to Try It Online (TIO). It seems you can save 2 bytes by putting all your code on one line. \$\endgroup\$ – Dingus Aug 3 '20 at 11:25
  • 1
    \$\begingroup\$ Thank you @Dingus for the encouragement and improvement. I also removed the parenthesis since it's Python 2. \$\endgroup\$ – Thomas Aug 3 '20 at 11:50
2
\$\begingroup\$

Integral, 416 Bytes

⌡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⌡[j

Try it

Integral doesn't have very many ways of doing this challenge yet, so this'll have to do for now.

I'll update it once there's a better way.

\$\endgroup\$
1
  • \$\begingroup\$ ah, beautiful solution. what an algorithm. \$\endgroup\$ – Razetime Sep 21 '20 at 12:57
2
\$\begingroup\$

LiveScript, 57 bytes

I noticed nobody had done LiveScript. This may not be the shortest possible answer, but it's my best attempt.

for i to 99
 console.log \Fizz *!(++i%3)+\Buzz *!(i%5)||i
\$\endgroup\$
2
\$\begingroup\$

MAWP 2.0, 60 bytes

[!3%<"Fizz":1=M>`!5%<"Buzz":1=M>`M1-{/!:\}`0=M10;!100-?.`1+]

Explanation:

[                start of loop
!3%              is top of stack divisible by 3?
<"Fizz":1=M>`    if yes, print "Fizz" and set variable M to 1
!5%              is top of stack divisible by 5?
<"Buzz":1=M>`    if yes, print "Buzz" and set variable M to 1
M1-              push value of M and subtract 1
{/!:\}`          if not 0 then print the current number
0=M              set variable M to 0
10;              print a newline
!100-?.`         if current number is 100 then terminate program
1+               add 1 to current number
]                end of loop
\$\endgroup\$
2
\$\begingroup\$

Charcoal, 37 29 bytes

E…¹¦¹⁰¹∨⁺×Fizz¬﹪ι³×Buzz¬﹪ι⁵Iι

Try it online!

How there isn't a charcoal answer yet amazes me. -8 bytes thanks to @Neil

Verbose

\$\endgroup\$
2
  • \$\begingroup\$ There are other minor variants such as Print(Map(100, Or(Add(Ternary(Modulo(Incremented(i), 3), "", "Fizz"), Ternary(Modulo(Incremented(i), 5), "", "Buzz")), Cast(Incremented(i))))); also for 29 bytes, but I do have a 28 byte solution... \$\endgroup\$ – Neil Sep 5 '20 at 23:52
  • \$\begingroup\$ I guess it's about time I reveal my 28 byte solution: E¹⁰⁰∨⭆⪪FiBu²⎇﹪⊕ι⁺³⊗μω⁺λzzI⊕ι. \$\endgroup\$ – Neil Oct 18 '20 at 18:04
2
\$\begingroup\$

Add++ -i, 46 bytes

L,100Rdd3€Ω%€!"Fizz"€*$5€Ω%€!"Buzz"€*z£+z£obUn

Try it online!

The flag simply invokes the function for us and outputs its return value, so we don't have to include the invocation in the program.

How it works

L,			; Anonymous function
	100R		; Push [1 2 3 4 ... 99 100]		STACK = [[1 2 ... 99 100]]
	dd		; Triplicate				STACK = [[1 2 ... 99 100] [1 2 ... 99 100] [1 2 ... 99 100]]
	 €  €		; Over the first, check ...
	3 Ω% !		;    divisibility by 3			STACK = [[1 2 ... 99 100] [1 2 ... 99 100] [0 0 ... 1 0]]
	"Fizz"€*	; Replace 1 with "Fizz" and 0 with ""	STACK = [[1 2 ... 99 100] [1 2 ... 99 100] ["" "" ... "Fizz" ""]
	$ €  €		; Over the second, check ...
	 5 Ω% !		;     divisibility by 5			STACK = [[1 2 ... 99 100] ["" "" ... "Fizz" ""] [0 0 ... 0 1]]
	"Buzz"€*	; Replace 1 with "Buzz" and 0 with ""	STACK = [[1 2 ... 99 100] ["" "" ... "Fizz" ""] ["" "" ... "" "Buzz"]]
	z£+		; Zip and concatenate			STACK = [[1 2 ... 99 100] ["" "" ... "Fizz" "Buzz"]]
	z£o		; Replace "" with the right number	STACK = [[1 2 ... "Fizz" "Buzz"]]
	bUn		; Join with newlines			STACK = ["1\n2\nFizz\n...\n98\nFizz\nBuzz"]
			; Return the top of the stack		"1\n2\nFizz\n...\n98\nFizz\nBuzz"
\$\endgroup\$
2
\$\begingroup\$

Add++, 89 bytes

l:100
Fl,`f,i%3,f=0,"Fizz"*f,`b,i%5,b=0,"Buzz"*b,`p,f+b,p="",Ip,,Oi,`c,f+b,`P,p=0,IP,,Oc,

Try it online!

"But there's a shorter Add++ answer" I hear you say. Well, this is flagless and doesn't have a Lambda, so I'd thought I'd post it for comparison.

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

MineFriff, 240 bytes

0,`
>I1,+:a*a1,=?;`~             o,aC            <  
>:f,%?`Ca*c2,:a*b7,7*e,a*c2,:f*7,a*7,oooooooo^
>:5,%?`Ca*c2,:a*b7,6*b,oooo                  ^
>:3,%?`Ca*c2,:f*7,a*7,oooo                   ^
>:o                                          ^

Try it online!

What it actually looks like:

300 px version Bigger

\$\endgroup\$
1
  • \$\begingroup\$ It's.. beautiful. \$\endgroup\$ – Razetime Oct 2 '20 at 4:33
1
5 6
7
8 9
12

Your Answer

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

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