183
\$\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, 2015 at 20:47
  • 1
    \$\begingroup\$ @AShelly Only when running \$\endgroup\$
    – Beta Decay
    Sep 24, 2015 at 20:48
  • 1
    \$\begingroup\$ I’m not sure I like the fact that you hardcoded the 100 into the challenge. That way, a program that just generates the expected output is a valid entry, but is not interesting for this challenge. I think the challenge should expect the program to input the number of items to output. \$\endgroup\$
    – Timwi
    Sep 24, 2015 at 23:28
  • 9
    \$\begingroup\$ @Timwi While I agree that it would make it (only slightly) more interesting, I've very often seen FizzBuzz as strictly 1 to 100 (on Wikipedia and Rosetta Code, for example). If the goal is to have a "canonical" FB challenge, it makes sense. \$\endgroup\$
    – Geobits
    Sep 25, 2015 at 0:50
  • 70
    \$\begingroup\$ A "vanilla fizzbuzz" sounds delicious. \$\endgroup\$ Sep 25, 2015 at 15:12

381 Answers 381

1
3 4
5
6 7
13
3
\$\begingroup\$

Ruby, 59

I wanted to make a Ruby version using the slick modulo/integer-division/string-multiplication trick from feersum's Python answer (though unfortunately Ruby doesn't handle string multiplication the same way, so I spent some bytes on that):

100.times{|i|puts "#{i+1}\r"+"Fizz"*(i%3/2)+"Buzz"*(i%5/4)}

Note that this uses a carriage return \r without a newline. I don't know how portable this is; it works on my Linux and should work on Linux in general, as well as on Mac, but I'm not sure how Windows handles it. Without that, here's a 61-byte version:

100.times{|i|puts ("Fizz"*(i%3/2)+"Buzz"*(i%5/4))[/.+/]||i+1}
\$\endgroup\$
2
  • \$\begingroup\$ You don't need space after puts. \$\endgroup\$
    – Vasu Adari
    Dec 7, 2015 at 3:20
  • \$\begingroup\$ Your first answer always prints the number even when it should only print the string \$\endgroup\$
    – Jo King
    Nov 21, 2021 at 23:25
3
\$\begingroup\$

Commodore Basic, 87 bytes

1F┌I=1TO100:F=F+1:B=B+1:IFF=3T|?"FIZZ";:F=0
2IFB=5T|?"BUZZ";:B=0
3IFF>0A/B>0T|?I;
4?:N─

Or in "shifted mode" to get both lower- and upper-case letters, but with the byte values of lowercase and uppercase swapped relative to ASCII-1967 (press COMMODORE+SHIFT):

1fOi=1to100:f=f+1:b=b+1:iff=3tH?"Fizz";:f=0
2ifb=5tH?"Buzz";:b=0
3iff>0aNb>0tH?i;
4?:nE

Usual PETSCII-to-Unicode substitutions: = SHIFT+O, | = SHIFT+H, / = SHIFT+N, = SHIFT+E

Commodore Basic doesn't have a "modulus" operation, so I need to use alternate methods to figure out when to print what: keeping a pair of counters turns out to be fewer bytes than dividing and checking for integer-ness. It also doesn't have a true logical "and" (despite the manual saying otherwise), so I need to do an explicit comparison against zero to decide if I should print the plain number.

\$\endgroup\$
1
  • \$\begingroup\$ @DLosc, you can switch into "shifted mode" which gives access to both upper- and lower-case, but with the character positions reversed relative to the ASCII-1967 which people are familiar with (eg. character #65 is lowercase "a" rather than uppercase). \$\endgroup\$
    – Mark
    Sep 28, 2015 at 2:27
3
\$\begingroup\$

Gol><>, 40 bytes

`e2RFL5%zR"zzuB"L3%zR"zziF"lQlRoaoC|LN|;

Updated for 0.4.0! I'm still tinkering with loops and trying to figure out how to do things best, but this is looking good so far.

Try it online.

Explanation

`e            Push 'e', or 101
2RF ... |     Execute F for loop twice - the first time activates the loop, and the
              second time updates it. This effectively makes the loop start from 1
L5%z          Push 1 if loop counter % 5 is 0, else 1
R"zzuB"       Push "Buzz" (top of stack) number of times
L3%z          Push 1 if loop counter % 3 is 0, else 1
R"zziF"       Push "Fizz" (top of stack) number of times
lQ ... |      If the stack is not empty...
  lRo         Output stack
  ao          Output newline
  C           Continue for loop
LN            Otherwise, print loop counter with newline

;             Terminate program

As we can see, there's a lot of abuse of R, which pops the top of the stack and executes the next instruction that many times.

\$\endgroup\$
1
  • \$\begingroup\$ That's a smart idea! Mind if I use it? \$\endgroup\$ Oct 28, 2015 at 12:16
3
\$\begingroup\$

Jolf, 42 33 31 bytes

Try it here! Replace ƒ with \x9f. I'm stealing ETHproduction's method of fizzbuzzing.

ƒΜz~1d|]"FizzBuzz"?%H340?%H548H

Old version, 42 bytes

γ"Fizz"ƒΜz~1d?mτͺ35H+γζ?m|3Hγ?m|5HΖ"Buzz"H
γ"Fizz"                                     γ = "Fizz"
        Μz~1d                               map 1..100 with the following function
             ?mτͺ35H                        if both 3 and 5 | H
                    +γζ                      return γ + ζ
                       m|3H                 else if 3 | H
                           γ                 return γ
                             ?m|5H          else if 5 | H
                                  Ζ"Buzz"    return ζ = "Buzz"
                                         H  else return H
       ƒ                                    join by newlines

I might be able to golf it down by using the dictionary in Jolf, but who would want to with such a perfect score?

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

D, 130 bytes

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

Ungolfed:

module FizzBuzz;

import std.stdio;
import std.conv;

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

Or, building a string, for 142 bytes,

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

Ungolfed:

module FizzBuzz;

import std.stdio;
import std.conv;

void main() {
  string x,y;
  for (
    int i;
    i++ < 100;
    x = ((i % 3 ? "" : "Fizz")
      ~ (i % 5 ? "" : "Buzz")),
    y ~= (x ? x : i.to!string) ~ "\n"
  ){};
  write(y);
}
\$\endgroup\$
3
\$\begingroup\$

Hoon, 126 bytes

%+
turn
(gulf [1 100])
|=
a/@
=+
[=((mod a 3) 0) =((mod a 5) 0)]
"{?:(-< "Fizz" "")}{?:(-> "Buzz" "")}{?:(=(- [| |]) <a> "")}"

Map over the list [1...100] with the function, interpolating the strings "Fizz" and "Buzz". If both mods are false, then it also interpolates the number.

This uses the fact that =+ pushes the value to the top of the context, which you can access with - and navigate with -< or -> for head/tail. Unfortunately, it looks pretty ugly because it needs a newline after runes to minimize byte count, along with not having built in operator functions.

I'm not entirely sure if this counts as a valid entry: It simply returns a list of strings to be printed by the shell, which is optimal. The other way would be to use ~& to print each element as it's mapped over, but it would still be rendered as "Fizz" or "Buzz" (with quotes) since it's a typed print, along with the shell then printing out the entire list anyways since it's the return value.

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

Vim, 66, 57 56 keystrokes

i1<esc>qqYp<C-a>q98@q3Gqy:s/\d*/Fizz<CR>3j@yq@y5Gqz:s<CR>ABuzz<esc>5j@zq@z

Further golfing, and explanation on the way.

\$\endgroup\$
1
  • \$\begingroup\$ A bit too late, but apparently this doesn't output correctly: Try it online! \$\endgroup\$
    – user41805
    May 16, 2017 at 9:47
3
\$\begingroup\$

Javascript, 56 bytes

for(f=0;f++<100;alert(f%5?b||f:b+'Buzz'))b=f%3?'':'Fizz'

Assuming 100 alerts is an acceptable output method.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Nice answer, but it's already been posted (That one originally used alert as well, but it was changed to console.log because all the other JS answers do the same) \$\endgroup\$ Mar 22, 2017 at 21:46
3
\$\begingroup\$

Ruby, 82 72 70 68 bytes

based on other answers:

puts (1..100).map{|i|(x=(i%3<1?"Fizz":"")+(i%5<1?"Buzz":""))>""?x:i}

old solution:

(1..100).map{|i|$><<"Fizz"if f=i%3<1
$><<"Buzz"if b=i%5<1
$><<i if !(f||b)
puts()}
\$\endgroup\$
1
3
\$\begingroup\$

AppleScript, 104 102 100 bytes

""
repeat with i from 1to 100
result&{"FizzBuzz",i,"Fizz","Buzz"}'s item((i^4mod 15+7)div 4)&"
"
end

If you run it in Script Editor, the result has "quotes" around it. If you run it with osascript, there are no "quotes", but the result ends with an extra blank line.

I steal the technique from Lynn's Lua answer, where the script picks from a list of possible values to print. I use (i^4mod 15+7)div 4 to calculate the index 1, 2, 3, or 4. It's different from Lua's i^2%3+i^4%5*2+1.

In AppleScript, i^4 raises i to 4th power. It returns a real, which is a floating-point number, but the value is equal to the correct integer.

The values of n = i^4mod 15 with i from 1 to 15 are

i = 1   2   3   4   5   6   7   8   9  10  11  12  13  14  15
n = 1   1   6   1  10   6   1   1   6  10   1   6   1   1   0

So n is 0.0 for "FizzBuzz", 1.0 for i, 6.0 for "Fizz", or 10.0 for "Buzz". This pattern continues with i from 16 to 100. I need to map the values 0.0, 1.0, 6.0, 10.0 to a list index; lists in AppleScript start at index 1.

n          = 0.0   1.0   6.0  10.0
(n+2)mod 7 = 2.0   3.0   1.0   5.0
(n+7)div 4 = 1     2     3     4

My 104-byte answer used (n+2)mod 7, but that mapping had 5.0 instead of 4.0, so it needed a list of 5 items, where the extra item 0, cost 2 bytes. My 102-byte answer uses (n+7)div 4. My 100-byte answer deletes 2 extra spaces.

\$\endgroup\$
3
+200
\$\begingroup\$

sed, 275 272 270 260 254 249 245 bytes

s/.*/t0u123456789/
:1
s/(tu?(.).*)/\1\n\2/
s/u(.)(t?)(.*)/\1\2u\3\1/
/9u/{s/t(.)/\1t/;s/u//;s/^/u/}
/99/!b1
s/$/\n10/
s/[0-9][05]/&Buzz/g
s/[0369]{2}/&Fizz/g
s/[147][258]/&Fizz/g
s/[258][147]/&Fizz/g
s/[0-9]+([FB])/\1/g
s/\n0/\n/g
s/[^\n]+\n//
q

Try it Online

This is a pure sed script which discards all input, if any, and then prints all the necessary output lines and quits.

Explanation

The script is divided into a sequence of three main parts: 1. Numeral generation; 2. "Fizz/Buzz/FizzBuzz" insertion; and 3. Formatting.

1. Numeral generation (lines 1 through 6)

The purpose of this part is to generate 99 lines containing the base 10 numerals corresponding to numbers 1 through 99. For that, we first set the entire pattern space to the following string:

t0u123456789

We will call the above string our state string. Next, we enter a loop in which each iteration goes like this:

  1. A newline is appended to the pattern space;
  2. A copy of the first numeral character after the "t" in the state string is appended to the pattern space;
  3. A copy of the first numeral character after the "u" in the state string is appended to the pattern space;
  4. The "u" in the state string is moved from its current position to the immediate right of the first numeral character after it or, if a "t" is already in said position, the "u" is instead moved to the immediate right of that "t";
  5. If the "u" in the state string is immediately at the right of the "9" in the state string, the "t" is moved from its current position to the immediate right of the first character after it, and the "u" is moved from its current position to the immediate left of the "0" in the state string;
  6. If there isn't a "99" anywhere in the pattern space (i.e., the loop has not finished its job of generating all the 99 lines), control goes back to line 2 (label :1) and so this enumeration of procedures is repeated from step 1; otherwise, control flow continues into the next line.

2. "Fizz/Buzz/FizzBuzz" insertion (lines 7 through 11)

The purpose of this part is to append "Fizz" immediately after each two-digit numeral in the pattern space which corresponds to a number which is a multiple of 3 but not of 5; to append "Buzz" immediately after each two-digit numeral in the pattern space which corresponds to a number which is a multiple of 5 but not of 3; and to append "FizzBuzz" after each two-digit numeral in the pattern space which corresponds to a number which is a multiple of both 3 and 5. This is how the computations go:

  1. We append a newline followed by "10" to the pattern space.
  2. Next, we search for all substrings of the pattern space formed by a digit between 0-9 on the left and either a 0 or a 5 on the right. We insert "Buzz" into the pattern space immediately after each such substring;
  3. Finally, we insert "Fizz" into the pattern space immediately after each substring which matches either of the following criteria:
    • Substrings formed by two digits which may be 0, 3, 6, or 9;
    • Substrings formed by a digit which is either 1, 4 or 7 on the left and a digit which is either 2, 5 or 8 on the right;
    • Substrings formed by a digit which is either 2, 5 or 8 on the left and a digit which is either 1, 4 or 7 on the right.

3. Formatting (lines 12 through 15)

This part is straight forward. Here we remove all of the following substrings from the pattern space:

  1. Every contiguous sequence of numeral characters on the immediate left of a "F" or a "B";
  2. All 0's on the immediate right of a newline character;
  3. All characters from the beginning of the pattern space up to and including the first newline character (remember that the state string is still there and there's a newline immediately before the first output numeral).

And then sed just prints the final contents of the pattern space and calls it quits.

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

Forth, 107 101 98 bytes

: f 101 1 do i 5 mod i 3 mod if dup if i . then else ." Fizz" then 0= if ." Buzz" then cr loop ; f

Ungolfed + close Python equivalent:

: f              \ def f():
  101 1 do       \     for i in range(1, 101):
    i 5 mod      \         a = i % 5  # Not an actual variable, pushed onto the stack
    i 3 mod      \         b = i % 3
    if           \         if b:      # b is popped
      dup        \             c = a
      if         \             if c:
        i .      \                 print(i, end='')
      then
    else         \         else:
      ." Fizz"   \             print('Fizz', end='')
    then 
    0=           \         a = (a == 0)
    if           \         if a:
      ." Buzz"   \             print('Buzz', end='')
    then
    cr           \         print()
  loop
; 
f                \ f()

Run it!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ To Taylor Scott: sorry for deleting the edit. I thought adding another language would be more meaningful \$\endgroup\$
    – Alex
    Apr 18, 2018 at 23:25
  • 1
    \$\begingroup\$ Alex, while this is definitely a more interesting answer you should feel free to leave multiple responses to challenges. \$\endgroup\$ May 16, 2018 at 14:18
3
\$\begingroup\$

Go, 130 129 134 bytes

package main;import."fmt";func main(){for i:=1;i<101;i++{o:="";if i%3<1{o+="Fizz"};if i%5<1{o+="Buzz"};if o==""{Print(i)};Println(o)}}

I wish i had ternary operators...

Edit: @Dust pointed out that I printed to stderr so my solution actually increased in size :(

Try it online!

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

12-BASIC, 73 55 50 bytes

FOR I=1TO 100?"FIZZ"*!(I%3)+"BUZZ"*!(I%5)OR I
NEXT

The first code golf program I've written in the language I'm creating.
I should probably avoid code golf while working on it though...

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

Julia 1.0, 72 bytes

(n->println([n,"Fizz","Buzz","FizzBuzz"][sum(n.%[1,3,5,5].<1)])).(1:100)

Not the shortest solution possible, but I like the obfuscation. Try it online!

Explanation

We apply an anonymous function (n->...) itemwise .( ) to the range 1:100.

The function body does this (using sample input n=5):

n.%[1,3,5,5]          # Modulo n by each of these numbers                     [0,2,0,0]
.<1                   # Itemwise, is each remainder zero?                     [true,false,true,true]
sum(  )               # Count number of trues in the array                    3
                      # This will be 4 for multiples of 15, 3 for multiples
                      # of 5, 2 for multiples of 3, and 1 for other numbers
[n,"F","B","FB"][  ]  # Index (1-based) into this array                       "Buzz"
println(  )           # Print, with a newline
\$\endgroup\$
3
\$\begingroup\$

Javascript, 80 bytes

for(i=1;i<101;i++){console.log(i%3==0?i%5==0?"FizzBuzz":"Fizz":i%5==0?"Buzz":i)}
\$\endgroup\$
1
  • \$\begingroup\$ To whoever downvoted this; you really should explain why. Especially considering Jey is a new contributor. \$\endgroup\$
    – Marie
    Feb 27, 2019 at 19:27
3
\$\begingroup\$

APL (Dyalog Unicode), 37 bytesSBCS

↑{∨/d←4/0=3 5|⍵:d/'FizzBuzz'⋄⍕⍵}¨⍳100

Try it online!

⍳100ɩndices 1…100

{ apply the following anonymous lambda to each of those:

 the argument; e.g. 20

3 5| the division remainder when that is divided by 3 and 5; e.g. [2,0]

0= Boolean mask where that is equal to 0; e.g. [0,1]

4/ replicate those numbers for 4 copies of each; e.g. [0,0,0,0,1,1,1,1]

d← assign that to d

∨/: if any of those are true (OR-reduction); e.g. true:

  d/'FizzBuzz' use d to mask the characters of the string; e.g. "Buzz"

  else:

⍕⍵ stringify the argument; e.g. "20"

 mix the list of strings into a matrix, so it prints right  

\$\endgroup\$
2
  • \$\begingroup\$ Art⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ \$\endgroup\$ Mar 30, 2021 at 15:42
  • \$\begingroup\$ @AndrewOgden Thank you! \$\endgroup\$
    – Adám
    Mar 30, 2021 at 15:58
3
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 137 121 114 bytes

I	X =X + 1
	O =EQ(REMDR(X,3)) 'Fizz'
	O =O EQ(REMDR(X,5)) 'Buzz'
	O =IDENT(O) X
	OUTPUT =O
	O =LT(X,100) :S(I)
END

Try it online!

Explanation:

					;* uninitialized variables start as ''
					;* which is coerced to 0 in computations
I	X =X + 1			;* Increment X
	O =EQ(REMDR(X,3)) 'Fizz'	;* if X mod 3 == 0, O = 'Fizz'
	O =O EQ(REMDR(X,5)) 'Buzz'	;* if X mod 5 == 0, concatenate O and 'Buzz'
	O =IDENT(O) X			;* if O is IDENTical to the empty string,
					;* set O to X
	OUTPUT =O			;* print O
	O =LT(X,100) :S(I)		;* set O to '' and if X < 100, goto I
END
\$\endgroup\$
3
\$\begingroup\$

Zsh, 105 78 68 66 61 bytes

Try it online!

for i ({1..100})(((i%3))||w=Fizz;((i%5))||w+=Buzz;<<<${w-$i})

-27 using simpler approach
-10 using parameter fallback
-2 thanks to @Dennis - kudos for the bash solution
-5 thanks to @GammaFunction


Original solution, using weird r flag... try it online

for ((;i++<100;));{f=$[i%3>0?0:4] b=$[i%5>0?0:4]
echo ${(r:$f::Fizz:)}${(r:$b::Buzz:)}`((f+b>0))||<<<$i`}
\$\endgroup\$
4
  • 1
    \$\begingroup\$ You don't need the last ; on the first line. A port to Bash takes 70 bytes, thus beating my answer. \$\endgroup\$
    – Dennis
    Aug 28, 2019 at 14:49
  • 1
    \$\begingroup\$ Also, you don't need the newline before the last } (which is missing in your answer). Try it online! \$\endgroup\$
    – Dennis
    Aug 28, 2019 at 14:56
  • \$\begingroup\$ the bash solution still wins for originality.. I couldn't port that crazy for expression to zsh \$\endgroup\$
    – roblogic
    Aug 28, 2019 at 15:01
  • 1
    \$\begingroup\$ 61, mostly thanks to subshells \$\endgroup\$ Oct 15, 2019 at 2:03
3
\$\begingroup\$

DIVSPL, 22 bytes

1..100
fizz=3
buzz=5
\$\endgroup\$
3
\$\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\$
3
\$\begingroup\$

Windows Batch, 149 bytes

@for /l %%N in (1 1 100)do @(set s=&set/a1/(%%N%%3^)||set s=Fizz&set/a1/(%%N%%5^)&&(if defined s (echo Fizz)else echo %%N)||call echo %%s%%Buzz)2>nul

The SET /A statements test the modulo 3 and 5 without using IF by intentionally dividing by zero and using && and || conditional command concatenation. Of course stderr must be disabled, but it still saves bytes vs an IF statement.

Windows Batch (unusual cmd.exe configuration, and environment assumption), 166 165 133 bytes

My original answer used delayed expansion, but the code to enable delayed expansion takes 32 bytes all on its own. However, some people have their cmd.exe configured to have delayed expansion enabled by default. For the small minority of people that configure cmd.exe this way, then the following is significantly shorter.

@for /l %%N in (1 1 100)do @(set 1=&set/a1/(%%N%%3^)||set 1=Fizz&set/a1/(%%N%%5^)||set 1=!1!Buzz&>nul set 1&&echo !1!||echo %%N)2>nul

Besides relying on an unusual cmd.exe configuration, it is also reliant on the absence of any environment variable names that begin with 1. This is normally safe because batch treats something like %1var% as batch parameter %1 followed by a string constant var - the trailing % would get stripped. So people are taught to never begin variable names with a digit.

\$\endgroup\$
3
\$\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, 2020 at 12:57
3
\$\begingroup\$

><>, 59 bytes

0v!oo:oo"Fiz"\
1<oan?*/!?%5$\!?%3;?)*aa::::::+
o"Buzz"/$0oo

Try it online!

Prints a trailing newline

How it works

0v...
.<... Initialises the stack with 0
.....

.....
1<................;?)*aa::::::+ Increment the counter and duplicate it a looooot
.....                           End the program if the counter is larger than 100 (10*10)

0..oo:oo"Fiz"\
.............\!?%3... Check if the counter is divisible by 3 and print Fizz if so
.....                 Also push a 0 to the stack

.......o         Swap the pushed 0 if it exists (otherwise it swaps two copies of the counter)
......./!?%5$... Check if the counter is divisible by 5 and print Buzz if so
o"Buzz"/$0oo     Also push a 0 to the stack

.......... Multiply the top two values of the stack. 
..oan?*... If the counter was divisible by 5 or 3 print the number
.......... Print a newline and loop around again

As time goes, the stack fills up, with an extra copy of the counter for each Fizz or Buzz (and two for FizzBuzzes). This is due to the extra copy(s) of the counter that don't end up being printed.

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

Python 3, 88 85 77 73 bytes

i=0
exec("i+=1;print(i%3*i%5and i or(i%3<1)*'Fizz'+(i%5<1)*'Buzz');"*100)

Try it online!

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

GNU AWK, 1 input byte + 60 bytes = 61 bytes

An approach different from Cabbie407's, that golfed 2 bytes off thanks to the more flexible parsing of the GNU's implementation. Still needs one EOF input.

END{for(;++n<101;print i?i:n)i=(n%3?e:"Fizz")(n%5?e:"Buzz")}

Try it online!

END              # starts after commanding the EOF (Ctrl+D).
{
for(;
    ++n<101;     # the _n_ variable is started here on the conditional, at the value 1.
    print i?i:n  # in the end of each loop, prints _i_ if non-null, or _n_.
   )
      i=(n%3?e:"Fizz")(n%5?e:"Buzz")
      # two ternary conditionals that concatenates Fizz and Buzz accordingly.
      # by the way, _e_ is a not assigned variable, which will return a null string ("").
      # if n != 0 (mod 15), then _i_ will return null at the print statement above.
}

For no input, use the BEGIN pattern instead (62 bytes total):

BEGIN{for(;++n<101;print i?i:n)i=(n%3?e:"Fizz")(n%5?e:"Buzz")}
\$\endgroup\$
3
\$\begingroup\$

jq, 45 bytes

range(100)+1|(1-.%3)*"fizz"+(1-.%5)*"buzz"//.
# explanation
range(100)+1| # for each number in range 0-99 + 1
      . % 3 ) #   the current number modulo 3
 ( 1 -        #   the important thing is this gives 1 for 0 and an invalid
              #   number (0 or negative) for any positive number
       *"fizz"#   "fizz" repeated that many times. For a negative or 0 number
              #   this returns null
 + ..."buzz"  #   concatenated with the same thing but for buzz.
              #   null + anything is that thing, so for a number not divisible by
              #   3 or 5 this returns null
   // .       #   if the result is null, the number itself
              # implicit output

For best results run with jq -rn '...' | less.

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

Turing Machine Code, 5743 bytes

Should note that Turing Machine Code doesn't process newlines/carriage returns. So everything is necessarily on one line. Thus this may not be, by strict interpretation of the rules, a competing answer due to the nature of the language.

0 * * * 1
1 * 1 r #
# * # * f
f * * l f
f 1 1 l !
f 2 2 l "
f 3 3 l £
f 4 4 l $
f 5 5 l %
f 6 6 l ^
f 7 7 l &
f 8 8 l `
f 9 9 l (
f 0 0 l )
f F F l f
f i i l f
f z z l f
f B B l f
f u u l f
) 1 1 * ¬
) 2 2 * -
) 3 3 * =
) 4 4 * +
) 5 5 * {
) 6 6 * }
) 7 7 * [
) 8 8 * ]
) 9 9 * :
! _ _ r '
! 1 1 r @
! 2 2 * ~
! 3 3 r \
! 4 4 r /
! 5 5 * ,
! 6 6 r .
! 7 7 r <
! 8 8 * >
! 9 9 r ?
" _ _ r a
" 1 1 * b
" 2 2 r c
" 3 3 r d
" 4 4 * e
" 5 5 r ƒ
" 6 6 r g
" 7 7 * h
" 8 8 r ï
" 9 9 r j
£ _ _ r k
£ 1 1 r l
£ 2 2 r m
£ 3 3 * n
£ 4 4 r o
£ 5 5 r p
£ 6 6 * q
£ 7 7 r r
£ 8 8 r s
£ 9 9 * t
$ _ _ r ü
$ 1 1 r v
$ 2 2 * w
$ 3 3 r x
$ 4 4 r y
$ 5 5 * ž
$ 6 6 r A
$ 7 7 r Ɓ
$ 8 8 * C
$ 9 9 r D
% _ _ r E
% 1 1 * Ϝ
% 2 2 * G
% 3 3 * H
% 4 4 * I
% 5 5 * J
% 6 6 * K
% 7 7 * L
% 8 8 * M
% 9 9 * N
^ _ _ r O
^ 1 1 r P
^ 2 2 r Q
^ 3 3 * R
^ 4 4 r S
^ 5 5 r T
^ 6 6 * U
^ 7 7 r V
^ 8 8 r W
^ 9 9 * X
& _ _ r Y
& 1 1 r Z
& 2 2 * α
& 3 3 r β
& 4 4 r γ
& 5 5 * δ
& 6 6 r ε
& 7 7 r ζ
& 8 8 * η
& 9 9 r θ
` _ _ r ι
` 1 1 * κ
` 2 2 r λ
` 3 3 r μ
` 4 4 * ν
` 5 5 r ξ
` 6 6 r ο
` 7 7 * π
` 8 8 r ρ
` 9 9 r ς
( _ _ r σ
( 1 1 r τ
( 2 2 r υ
( 3 3 * φ
( 4 4 r χ
( 5 5 r ψ
( 6 6 * ω
( 7 7 r Α
( 8 8 r Β
( 9 9 * Γ
@ * * r @
@ # _ r Δ
Δ _ 1 r Ε
Ε _ 2 r F
' * * r '
' # _ r 2
2 _ 2 r #
~ * * r ~
~ 2 _ r ~
~ 1 _ r ~
~ # _ r Ζ
Ζ _ 2 r 2
\ * * r \
\ # _ r Η
Η _ 3 r 2
/ * * r /
/ # _ r Θ
Θ _ 4 r Ε
, * * r ,
, 5 _ r ,
, 1 _ r ,
, # _ r Ι
Ι _ 5 r 2
. * * r .
. # _ r Κ
Κ _ 6 r 2
< * * r <
< # _ r Λ
Λ _ 7 r Ε
> * * r >
> 8 _ r >
> 1 _ r >
> # _ r Μ
Μ _ 8 r 2
? * * r ?
? # _ r Ν
Ν _ 9 r 2
a * * r a
a # _ r Ξ
Ξ _ 3 r F 
3 _ 3 r #
b * * r b
b 1 _ r b
b 2 _ r b
b # _ r Ο
Ο _ 1 r 3
c * * r c
c # _ r Π
Π _ 2 r 3
d * * r d
d # _ r Ρ
Ρ _ 3 r Ξ
e * * r e
e 4 _ r e
e 2 _ r e
e # _ r Σ
Σ _ 4 r 3
ƒ * * r ƒ
ƒ # _ r Τ
Τ _ 5 r 3
g * * r g
g # _ r Υ
Υ _ 6 r Ξ
h * * r h
h 7 _ r h
h 2 _ r h
h # _ r Φ
Φ _ 7 r 3
ï * * r ï
ï # _ r Χ
Χ _ 8 r 3
j * * r j
j # _ r Ψ
Ψ _ 9 r Ξ
k * * r k
k 3 _ r k
k # _ r 4
4 _ 4 r #
Ω _ 4 r F
l * * r l
l # _ r ¤
¤ _ 1 r 4
m * * r m
m # _ r ¥
¥ _ 2 r Ω
n * * r n
n 3 _ r n
n # _ r ¦
¦ _ 3 r 4
o * * r o
o # _ r ¨
¨ _ 4 r 4
p * * r p
p # _ r ©
© _ 5 r Ω
q * * r q
q 6 _ r q
q 3 _ r q
q # _ r ª
ª _ 6 r 4
r * * r r
r # _ r «
« _ 7 r 4
s * * r s
s # _ r ®
® _ 8 r Ω
t * * r t
t 9 _ r t
t 3 _ r t
t # _ r °
° _ 9 r 4
ü * * r ü
ü # _ r ±
± _ 5 r B 
v * * r v
v # _ r ²
² _ 1 r ³
³ _ 5 r Ƒ
5 _ 5 r #
w * * r w
w 2 _ r w
w 4 _ r w
w # _ r ¶
¶ _ 2 r ±
x * * r x
x # _ r ·
· _ 3 r ±
y * * r y
y # _ r ¸
¸ _ 4 r ³
ž * * r ž
ž 5 _ r ž
ž 4 _ r ž
ž # _ r ¹
¹ _ 5 r ±
A * * r A
A # _ r »
» _ 6 r ±
Ɓ * * r Ɓ
Ɓ # _ r ¼
¼ _ 7 r ³
C * * r C
C 8 _ r C
C 4 _ r C
C # _ r ½
½ _ 8 r ±
D * * r D
D # _ r ¾
¾ _ 9 r ±
E * * r E
E # _ r ¿
E 5 _ r E
¿ _ 6 r F 
6 _ 6 r #
Ϝ * * r Ϝ
Ϝ 1 _ r Ϝ
Ϝ 5 _ r Ϝ
Ϝ # _ r À
À _ 1 r 6
G * * r G
G 2 _ r G
G 5 _ r G
G # _ r Á
Á _ 2 r 6
H * * r H
H 3 _ r H
H 5 _ r H
H # _ r Â
 _ 3 r ¿
I * * r I
I 4 _ r I
I 5 _ r I
I # _ r Ã
à _ 4 r 6
J * * r J
J 5 _ r J
J # _ r Ä
Ä _ 5 r 6
K * * r K
K 6 _ r K
K 5 _ r K
K # _ r Å
Å _ 6 r ¿
L * * r L
L 7 _ r L
L 5 _ r L
L # _ r Æ
Æ _ 7 r 6
M * * r M
M 8 _ r M
M 5 _ r M
M # _ r Ç
Ç _ 8 r 6
N * * r N
N 9 _ r N
N 5 _ r N
N # _ r È
È _ 9 r ¿
O * * r O
O 6 _ r O
O # _ r 7
7 _ 7 r #
É _ 7 r F
P * * r P
P # _ r Ê
Ê _ 1 r 7
Q * * r Q
Q # _ r Ë
Ë _ 2 r É
R * * r R
R 3 _ r R
R 6 _ r R
R # _ r Ì
Ì _ 3 r 7
S * * r S
S # _ r Í
Í _ 4 r 7
T * * r T
T # _ r Ï
Ï _ 5 r É
U * * r U
U 6 _ r U
U # _ r Ð
Ð _ 6 r 7
V * * r V
V # _ r Ñ
Ñ _ 7 r 7
W * * r W
W # _ r Ò
Ò _ 8 r É
X * * r X
X 9 _ r X
X 6 _ r X
X # _ r Ó
Ó _ 9 r 7
Y * * r Y
Y # _ r 8
8 _ 8 r #
Z * * r Z
Z # _ r Ô
Ô _ 1 r Õ
Õ _ 8 r F
α * * r α
α 2 _ r α
α 7 _ r α
α # _ r Ö
Ö _ 2 r 8
β * * r β
β # _ r ×
× _ 3 r 8
γ * * r γ
γ # _ r Ø
Ø _ 4 r Õ
δ * * r δ
δ 5 _ r δ
δ 7 _ r δ
δ # _ r Ù
Ù _ 5 r 8
ε * * r ε
ε # _ r Ú
Ú _ 6 r 8
ζ * * r ζ
ζ # _ r Û
Û _ 7 r Õ
η * * r η
η 8 _ r η
η 7 _ r η
η # _ r Ü
Ü _ 8 r 8
θ * * r θ
θ # _ r Ý
Ý _ 9 r 8
ι * * r ι
ι # _ r Ā
Ā _ 9 r F 
9 _ 9 r #
κ * * r κ
κ 1 _ r κ
κ 8 _ r κ
κ # _ r Ă
Ă _ 1 r 9
λ * * r λ
λ # _ r Ą
Ą _ 2 r 9
μ * * r μ
μ # _ r Ć
Ć _ 3 r Ā
ν * * r ν
ν 4 _ r ν
ν 8 _ r ν
ν # _ r Ĉ
Ĉ _ 4 r 9
ξ * * r ξ
ξ # _ r Ċ
Ċ _ 5 r 9
ο * * r ο
ο # _ r Đ
Đ _ 6 r Ā
π * * r π
π 7 _ r π
π 8 _ r π
π # _ r Ē
Ē _ 7 r 9
ρ * * r ρ
ρ # _ r Ĕ
Ĕ _ 8 r 9
ς * * r ς
ς # _ r Ė
Ė _ 9 r Ā
Č _ 0 r #
σ * * r σ
σ # _ r Ę
σ 9 _ r σ
Ę _ 1 r Ď
Ď _ 0 r B
τ * * r τ
τ # _ r Ě
Ě _ 2 r Ď
υ * * r υ
υ # _ r Ĝ
Ĝ _ 3 r Ğ
Ğ _ 0 r Ƒ
φ * * r φ
φ 3 _ r φ
φ 9 _ r φ
φ # _ r Ġ
Ġ _ 4 r Ď
χ * * r χ
χ # _ r Ģ
Ģ _ 5 r Ď
ψ * * r ψ
ψ # _ r Ĥ
Ĥ _ 6 r Ğ
ω * * r ω
ω # _ r Ħ
ω 6 _ r ω
ω 9 _ r ω
Ħ _ 7 r Ď
Α * * r Α
Α # _ r Ĩ
Ĩ _ 8 r Ď
Β * * r Β
Β # _ r Ī
Ī _ 9 r Ğ
Γ * * r Γ
Γ 9 _ r Γ
Γ # _ r Ĭ
Ĭ _ B r Į
Į _ u r İ
İ _ z r IJ
IJ _ z r halt
Ĵ _ 1 r #
Ķ _ 1 r F
¬ * * r ¬
¬ 1 _ r ¬
¬ 0 _ r ¬
¬ # _ r Ĺ
Ĺ _ 1 r Ĵ
- * * r -
- 2 _ r -
- 0 _ r -
- # _ r Ļ
Ļ _ 2 r Ķ
= * * r =
= 3 _ r =
= 0 _ r =
= # _ r Ľ
Ľ _ 3 r Ĵ
+ * * r +
+ 4 _ r +
+ 0 _ r +
+ # _ r Ŀ
Ŀ _ 4 r Ĵ
{ * * r {
{ 5 _ r {
{ 0 _ r {
{ # _ r Ł
Ł _ 5 r Ķ
} * * r }
} 6 _ r }
} 0 _ r }
} # _ r Ń
Ń _ 6 r Ĵ
[ * * r [
[ 7 _ r [
[ 0 _ r [
[ # _ r Ň
Ň _ 7 r Ĵ
] * * r ]
] 8 _ r ]
] 0 _ r ]
] # _ r Ņ
Ņ _ 8 r Ķ
: * * r :
: 9 _ r :
: 0 _ r :
: # _ r Ŋ
Ŋ _ 9 r Ĵ
F _ F r i
i _ i r ȥ
ȥ _ z r ź
ź _ z r #
Ƒ _ F r í
í _ i r ż
ż _ z r ƶ
ƶ _ z r B
B _ B r u
u _ u r z
z _ z r ź

Try it online!

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

Perl 5 (ppencode-compatible), 1232 690 bytes

Today I learned that and has higher precidence than or or xor; I suffered from making a proper control flow

eval q y eval q x ord or return cos while chop and chop and chop x and print chr ord uc qw q for q and print chr ord q tie gt and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc y xor eval q y print uc chr ord q dbmopen and and print chr ord q dump and and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos if length q q s s q eq chr ord reverse length or not chr ord reverse length y or eval q x print length unless length q q s s q eq chr ord reverse length or not chr ord reverse length x xor print chr hex qw q and q while s qq q and length ne ord qw q eq

Try it online!

How it works

# fizz part
eval q y
   # if(length%3==0)
   eval q x
      # instead of length or return 1
      ord or return cos
   while
      # instead of s/...//
      chop and chop and chop
   x and
 
   # print 'Fizz'
   print chr ord uc qw q for q and
   print chr ord q tie gt and
   print chr length q else x oct oct ord q eq le and
   print chr length q else x oct oct ord q eq le and

   # for truthy
   return cos
for
   # instead of $_
   uc
y

xor

# buzz part
eval q y
   # print 'Buzz'
   print uc chr ord q dbmopen and and
   print chr ord q dump and and
   print chr length q else x oct oct ord q eq le and
   print chr length q else x oct oct ord q eq le and

   # for truthy
   return cos
if
   # instead of length%5, /[05]$/
   length q q s s q eq chr ord reverse length or
   not chr ord reverse length
y

or

# this block is done when length%15==0 or length%3&&length%5
eval q x
   print length
unless
   # instead of length%5
   length q q s s q eq chr ord reverse length or
   not chr ord reverse length
x

xor

# newline
print chr hex qw q and q


while
   s qq q and

   # ord qw q eq == 101
   length ne ord qw q eq

Previous

eval q y eval q kill and length or return cos while s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and ok and print chr ord uc qw q for q and print chr ord q tie gt and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and print uc chr ord q dbmopen and and print chr ord q dump and and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc y or eval q y eval q kill and length or return cos while s q qq and s q qq and s q qq and s q qq and s q qq and ok and print uc chr ord q dbmopen and and print chr ord q dump and and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc y or eval q y eval q kill and length or return cos while s q qq and s q qq and s q qq and ok and print chr ord uc qw q for q and print chr ord q tie gt and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc y or print length xor print chr length q q x x x x eq while s qq q and length ne ord qw q eq

Try it online!

Explained

# fizzbuzz part
eval q y
   # length%15==0?
   eval q k
         ill and length or return cos
      while
s q qq and s q qq and s q qq and
s q qq and s q qq and s q qq and
s q qq and s q qq and s q qq and
s q qq and s q qq and s q qq and
s q qq and s q qq and s q qq and o
   k and
   # then print FizzBuzz, as in first ppencode
   print chr ord uc qw q for q and
   print chr ord q tie gt and
   print chr length q else x oct oct ord q eq le and
   print chr length q else x oct oct ord q eq le and
   print uc chr ord q dbmopen and and
   print chr ord q dump and and
   print chr length q else x oct oct ord q eq le and
   print chr length q else x oct oct ord q eq le and
   # cos is for TRUTHY
   return cos
 # don't change $_ outside 
 for uc
# buzz part, like above
y or eval q y
   eval q kill and length or return cos while s q qq and s q qq and s q qq and s q qq and s q qq and ok and print uc chr ord q dbmopen and and print chr ord q dump and and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc
# fizz part, like above
y or eval q y
   eval q kill and length or return cos while s q qq and s q qq and s q qq and ok and print chr ord uc qw q for q and print chr ord q tie gt and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc
# no special strings
y or print length
# print LF
xor print chr length q q x x x x eq
# pretty familiar, isn't it?
while s qq q and length ne ord qw q eq
\$\endgroup\$
0
1
3 4
5
6 7
13

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.