203
\$\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>

Toby Speight
6,9941 gold badge30 silver badges43 bronze badges
asked Sep 24, 2015 at 19:23
\$\endgroup\$
15
  • 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\$ Commented Sep 24, 2015 at 20:47
  • 1
    \$\begingroup\$ @AShelly Only when running \$\endgroup\$ 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\$ Commented Sep 24, 2015 at 23:28
  • 10
    \$\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\$ Commented Sep 25, 2015 at 0:50
  • 77
    \$\begingroup\$ A "vanilla fizzbuzz" sounds delicious. \$\endgroup\$ Commented Sep 25, 2015 at 15:12

436 Answers 436

1
...
11 12 13
14
15
1
\$\begingroup\$

Nim, 72 bytes

for i in 1..100:echo max(["Fizz",""][i*i%%3]&["Buzz",""][ord i%%5>0],$i)

Try it online!

answered May 3, 2022 at 2:02
\$\endgroup\$
1
\$\begingroup\$

Raku, 44 bytes

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

Try it online!

answered May 3, 2022 at 21:14
\$\endgroup\$
1
\$\begingroup\$

SQLite, 183 bytes

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

Try it online!

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

Squirrel, 131 bytes

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

Try it online!

This is the original code that I created:

function fizzBuzz(n) {
 for (local i = 1; i <= n; i += 1) {
 if (i % 15 == 0)
 print ("FizzBuzz\n")
 else if (i % 5 == 0)
 print ("Buzz\n")
 else if (i % 3 == 0)
 print ("Fizz\n")
 else {
 print (i + "\n")
 }
 }
}
fizzBuzz(100);
answered May 14, 2022 at 20:23
\$\endgroup\$
1
\$\begingroup\$

Pascal, 162 B

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

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

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

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

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

answered Nov 5, 2022 at 11:58
\$\endgroup\$
1
\$\begingroup\$

Phooey, (削除) 53 48 (削除ここまで)47 bytes

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

Try it online!

Outgolfed the creator at his own language. 😏


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

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

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

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

Assembly (MIPS, SPIM), 202 bytes

main:add7ドル 1
li2ドル 4
la4ドル F
rem6ドル 7ドル 3
bnez6ドル n
syscall
n:rem5ドル 7ドル 5
bnez5ドル o
or4ドル 5
syscall
j e
o:beqz6ドル e
abs4ドル 7ドル
li2ドル 1
syscall
e:li2ドル 11
li4ドル 10
syscall
bne7ドル'd'main
j$ra
.data
F:.asciiz"Fizz""Buzz"

Try it online!

Explanation

This does a lot of SPIM abuse 😏

This assumes the following features of an empty program:

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

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

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

sssnnsssnssstntssssnsssststtstsstnsstttnnstnssstttstttststnssttstnnstntssnntstnsnstnstnsstnssststsnsnssnstnsstssntsstnttsnnnnnssnstssttnsnttsttnttssnsnssssttsssstntstttnsstnsssssttttstsnsnstnsstnsssssnnssssnntn

Show result on ideone

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

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

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

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

Pyt, 91 bytes

11`ŕĐĐ5%⇹3%?ŕ:ŕ8⬡2+ƇĐ2ᴇ5+Ƈ7⬠Ƈ5Ș;?ŕ:ŕ8⬡2+ƇĐ9⬠Ƈ6⬡Ƈ4Ș;ǰĐĐąɬɔĐƩ?ŕ⇹ą⇹*ǰ⇹ąɬą\ǰƖ⇹ƥ:ŕŕŕƖĐƥ;+Đ2ᴇ+<łĉ

Try it online!

Code Action
1 Pushes 1
1`ŕ...ł Do... while top of stack is truthy
ĐĐ5%⇹3% Gets n mod 5 and n mod 3
?ŕ:ŕ8⬡2+ƇĐ2ᴇ5+Ƈ7⬠Ƈ5Ș; If n mod 3 is 0, push "Fizz"
?ŕ:ŕ8⬡2+ƇĐ9⬠Ƈ6⬡Ƈ4Ș; If n mod 5 is 0, push "Buzz"
ǰĐĐąɬɔĐƩ?ŕ⇹ą⇹*ǰ⇹ąɬą\ǰƖ⇹ƥ:ŕŕŕƖĐƥ; If the stack contains any letters, print only the letters; otherwise, print the number
+Đ2ᴇ+< Is the number less than 100?
ĉ Clears the stack
answered Jan 28, 2023 at 17:17
\$\endgroup\$
1
\$\begingroup\$

Thunno H N, \$ 27 \log_{256}(96) \approx \$ 22.22 bytes

e1+D35d%0="FBiuzzzz"Zlz*Js~

Attempt This Online!

Thunno H d, \32ドル \log_{256}(96) \approx\$ 26.34 bytes

R{1+zt3%!"Fizz"*s5%!"Buzz"*+s~ZK

Attempt This Online!

Explanations:

 # The H flag implicitly pushes 100 to the stack
e1+ # Map over range(100) and add one each time:
 D # Duplicate the number
 35d # Push the digits of 35 - [3, 5]
 %0= # Push [divisible by 3, divisible by 5]
"FBiuzzzz" # Push string "FBiuzzzz"
Zl # Uninterleave to get ["Fizz", "Buzz"]
 z*J # Multiply element-wise and join
 s~ # Swap and logical or with the number
 # After the map, the N flag joins by newlines
 # The H flag implicitly pushes 100 to the stack
R{ # Loop through range(100):
 1+ # Add one
 zt # Triplicate so it is on the stack three times
 3%! # Is it divisible by 3?
"Fizz"* # Multiply this by the string "Fizz"
 # i.e. push "Fizz" if it's divisible by 3, "" otherwise
 s # Swap so the number is back on top
5%! # Is it divisble by 5?
 "Buzz"* # Multiply this by the string "Buzz"
 # i.e. push "Buzz" if it's divisible by 5, "" otherwise
+ # Add them togther, so we have "Fizz", "Buzz", "FizzBuzz", or ""
 s~ # Swap and perform `or`, so we get the number if it's ""
 ZK # Print with a newline
 # After the loop, the d flag stops the implicit output
answered Jan 4, 2023 at 11:18
\$\endgroup\$
1
\$\begingroup\$

Minecraft Function, 666 bytes

scoreboard objectives add c dummy
scoreboard players add c c 1
scoreboard players set 0 c 0
scoreboard players set 3 c 3
scoreboard players set 5 c 5
scoreboard players operation f c = c c
scoreboard players operation b c = c c
scoreboard players operation f c %= 3 c
scoreboard players operation b c %= 5 c
execute if score f c > 0 c if score b c > 0 c run tellraw @a {"score":{"name":"c","objective":"c"}}
execute if score f c = 0 c if score b c > 0 c run tellraw @a "Fizz"
execute if score f c > 0 c if score b c = 0 c run tellraw @a "Buzz"
execute if score f c = 0 c if score b c = 0 c run tellraw @a "FizzBuzz"
execute if score c c matches ..99 run function a:b

Must be run as a function named a in a data pack named b. I think this is about optimal for a scoreboard based solution.

Commented version:

# Create scoreboard to store variables
scoreboard objectives add c dummy
# Increment counter by 1 (starts at 0)
scoreboard players add c c 1
# Set constants 0, 3, and 5 for comparison and modulo
scoreboard players set 0 c 0
scoreboard players set 3 c 3
scoreboard players set 5 c 5
# Copy value of counter to f and b and modulo them by 3 and 5 respectively.
scoreboard players operation f c = c c
scoreboard players operation b c = c c
scoreboard players operation f c %= 3 c
scoreboard players operation b c %= 5 c
# If f and b are both > 0, print the counter
execute if score f c > 0 c if score b c > 0 c run tellraw @a {"score":{"name":"c","objective":"c"}}
# If f = 0 and b > 0, print Fizz
execute if score f c = 0 c if score b c > 0 c run tellraw @a "Fizz"
# If f > 0 and b > 0, print Buzz
execute if score f c > 0 c if score b c = 0 c run tellraw @a "Buzz"
# If both are 0 print FizzBuzz (Minecraft doesn't support string concatenation so this is necessary)
execute if score f c = 0 c if score b c = 0 c run tellraw @a "FizzBuzz"
# Run the function again if the counter is <= 99
execute if score c c matches ..99 run function a:b
answered Aug 5, 2023 at 16:35
\$\endgroup\$
1
\$\begingroup\$

Aubergine, 225 bytes ( 222 bytes with error )

:Ba=aA-A1=ba-b1:BA-Ai+Ai+a1=bi=oA+a1:bA+a1+iA=a1-ii?		0円B*Fizz0円0円FBuzz0円[-aa=aA-aA+ai-ai=bi-bi+iA=ab-a1=oA=oB=bi-bi+B1+b1=oB+b1-aa:aB+ii=a1=aA+A1+A1-aa=aA-a1-a1=bA-a1-bA=Ab-ib-a1-AA-a1-AA-aa-a1-A1-a1=bA-a1-Ab-a1+A1-a1-iAo01

* four 0円 mean NUL(ASCII 0) character

Try it online!

The equivalent pseudo code in C is like below;


#include <stdio.h>
#include <stdint.h>
#define I(x) ((intptr_t)&&x)
#define P(x) *(void*)(x)
static void nop(void) {}
int main(void) {
 intptr_t
  *cp,*cpt,t,p,
  pvars0[] =
   { I(Tj3)-I(Tj1), I(Tj2)-I(Tj1), I(Tj2)-I(Tj1), 0, I(Tc1)-I(Tj3),
    I(Lb), 3, 'F', 'i', 'z', 'z', 0, I(Lb)-I(Tx2), },
  pvars1[] =
   { I(Lj), 5, 'B', 'u', 'z', 'z', 0, I(Lc)-I(Tx2), },
  dvars[] = { I(Tc2)-I(Tj3), '0', '1', '\n', 10, },
  *pbase[] = { &pvars0[6], &pvars1[1] },
  *dbase3=&dvars[2], *dbase1=&dvars[4];
 int i=0;
Lx: // Fizz/Buzz print ( i=0 for Fizz, i=1 for Buzz )
 // decrement counter
 cp = pbase[i];
 *cp-=1;
 if ( *cp!=0 ) goto P(*(cp-1)); // skip printing and jump to Lb/Jj
 *cp+=3; // restore the counter to 3 ( add more 2 for Buzz in Lc )
 cp+=1;
 p=I(Tx1);
Tx1: // putchar loop
 putchar(*cp);
 cp+=1;
 if ( *cp!=0 ) goto P(p); // jump to Tx1
 goto P(I(Tx2)+*(cp+1)); // jump to Lb/Lc
Tx2:
Lb: // Buzz print
 i=1;
 goto Lx;
Lj: // number print and post process
 cp=pbase[0];
 // select &pvars[0] thru &pvars[2] as jump offset
 cp-=*cp;
 cp-=3;
 cpt=dbase3;
 goto P( I(Tj1)+*cp ); // jump to Tj3(when Fizz) or Tj1/Tj2
Tj1: // print the upper digit
 cp=cpt-1;
 putchar(*cp);
Tj2: // print the lower digit
 putchar(*cpt);
Tj3: // print a new line and increment the lower digit
 cp=dbase3;
 *cp+=1;
 cp+=1;
 putchar(*cp);
 cp+=1;
 i=0;
 if ( *cp!=0 ) goto Lx; // next iteration
 return 0; // exit
Lc: // after Buzz
 // add more 2 to the Buzz counter
 cp=pbase[1];
 *cp+=2;
 // switch pvars0[3] ( jump offset ) between 0 and pvars0[4]
 cp=pbase[0]-2;
 t=*cp;
 cp-=1;
 t-=*cp;
 *cp=t;
 goto P( I(Tc1)-t ); // jump to Tc1/Tj3
Tc1: // carry up
 // reset jump offsets in pvars[1],pvars[2]
 // so that the 1st "goto" in Lj jump to Tj1 instead of Tj2
 cp-=1;
 *cp=0;
 cp-=1;
 *cp=0;
 // decrement global loop counter
 cp=dbase1;
 *cp-=1;
 // decrease the lower digit by 10
 cp-=1;
 t=*cp;
 cp-=1;
 *cp-=t;
 // increment the upper digit
 cp-=1;
 *cp+=1;
 cp-=1;
 goto P(I(Tc2)-*cp); // jump to Tj3
Tc2:
 nop(); // not reached
}

Each code block handles;

  • Label Lx
    Print Fizz ( when i=0 ) or Buzz ( when i=1 ) if n is the multiple of 3 or 5.
  • Label Lb
    Just jump to Lx after setting i=1.
  • Label Lj
    Print n itself ( when Fizz or Buzz are not printed ) and do post-process.
  • Label Lc
    Carry-up operation.

In Aubergine code, each address range corresponds to;

  • 0 thru 2
    The 1st instruction :Ba has no effect, but stores pbase[].
    pbase[0] is ord(':')=58, pbase[1] is ord('B')=66.
  • 3 thru 50
    The code block with label Lx.
    Lx: =aA-A1=ba-b1:BA-Ai+Ai+a1=bi=oA+a1:bA+a1+iA, Tx1: =a1-ii
    * set i=0 ( -ii ) to implement goto Lx
  • 51
    A blank area.
  • 52 thru 72
    Stores pvars0[] and pvars1[]
  • 73 thru 135
    The code block with Label Lj.
    Lj: -aa=aA-aA+ai-ai=bi-bi+iA, Tj1: =ab-a1=oA, Tj2: =oB, TJ3: =bi-bi+B1+b1=oB+b1-aa:aB+ii
    The last instruction +ii jumps to an address out of range to stop the program.
  • 136 thru 219
    The code block with Label Lc.
    Lc: =a1=aA+A1+A1-aa=aA-a1-a1=bA-a1-bA=Ab-ib, Tc1: -a1-AA-a1-AA-aa-a1-A1-a1=bA-a1-Ab-a1+A1-a1-iA
  • 220 thru 224
    Stores dvars[]
    This area is accessed via minus addresses such as dbase1=-1 or dbase3=-3.

The 222 bytes version, which is shown below, outputs some error.

:Ba=aA-A1=ba-b1:BA-Ai+Ai+a1=bi=oA+a1:bA+a1+iA=a1-ii?		0円Q*Fizz0円0円\x9aBuzz0円=a1=aA+A1+A1-aa=aA-a1-a1=bA-a1-bA=Ab+ib-a1-AA-a1-AA-aa-a1-A1-a1=bA-a1-Ab-a1+A1-a1+iA-aa=aA-aA+ai-ai=bi-bi+iA=ab-a1=oA=oB=bi-bi+B1+b1=oB+b1-aa:aB01ドル

* 0円 is NUL, and \x9a is a byte 232

This code cannot be run on TIO because TIO requires codes to be UTF-8 clean. ( a single \x9a is not valid as UTF-8 byte sequence )

The differences between 225B version and this 222B version are;

  • Exchange the position in code of the Lj code block and the Lc code block.
  • Replace relative backward jump instructions -ib, -iA in Lc code block to forward jumps +ib, +iA.
  • Omit the instruction +ii, which works to stop the code, from Lj code block.
    * The code stops in error when the instruction pointer points the dvars area just after the Lj code block.
answered Aug 27, 2023 at 8:29
\$\endgroup\$
1
\$\begingroup\$

sclin, 63 bytes

100I-a \; tap
"Fizz""Buzz", over3 5, % ! ** c>< dup \pop |# n>o

Try it on scline!

My collection grows once again

answered Sep 8, 2023 at 0:20
\$\endgroup\$
1
\$\begingroup\$

gnuplot, (削除) 72 (削除ここまで) 68 bytes

se pr'-'
do for[i=1:100]{pr i%15?i%5?i%3?i:"Fizz":"Buzz":"FizzBuzz"}

Try it online!

Not sure whether the statement se pr'-' (set output to the console) would be allowed to be moved to the header, so, let's keep it in the body.

answered Jul 17, 2024 at 20:25
\$\endgroup\$
1
  • \$\begingroup\$ You don't need any of those parentheses \$\endgroup\$ Commented Jul 18, 2024 at 2:10
1
\$\begingroup\$

J, 47 bytes

echo(0{[:\:~":,:'FizzBuzz'#~4#0=3 5&|)"0>:i.100

Attempt This Online!

or, if you assume implicit echo like in Jconsole, as the other leading J solution here does, then you can remove the echo from the start for 43 bytes.

There seem to be shorter solutions on code.golf but solutions are private there so I don't know what they are... For now this can be the shortest we have on CGCC.

 NB. this runs for each 1 to 100, consider the 80th line.
 (0=3 5&|) 80
0 1
 (4#0=3 5&|) 80
0 0 0 0 1 1 1 1
 ('FizzBuzz'#~4#0=3 5&|) 80
Buzz
 (":,:'FizzBuzz'#~4#0=3 5&|) 80
80
Buzz
 ([:\:~":,:'FizzBuzz'#~4#0=3 5&|) 80
 NB. sort reverse-lexicographically; n only wins if s is empty
Buzz
80
 (0{[:\:~":,:'FizzBuzz'#~4#0=3 5&|) 80
Buzz
answered Jul 21, 2024 at 7:38
\$\endgroup\$
1
\$\begingroup\$

tinylisp 2, 80 bytes

(quiet(m(\(N)(w(?(% N 3)(?(% N 5)N"Buzz")(?(% N 5)"Fizz""FizzBuzz"))nl))(1to 100

Try It Online!

Ungolfed/explanation

We map a lambda function over the numbers from 1 to 100. For each number N:

  • Is it nonzero mod 3?
    • Is it nonzero mod 5? Then return N
    • Else, return "Buzz"
  • Else:
    • Is it nonzero mod 5? Then return "Fizz"
    • Else, return "FizzBuzz"

We then write this value, followed by a newline. Since write returns nil, the result of the map is a list of 100 copies of nil. We prevent the interpreter from outputting this list by passing it to quiet.

(quiet
 (map
 (lambda (N)
 (write
 (if (% N 3)
 (if (% N 5)
 N
 "Buzz")
 (if (% N 5)
 "Fizz"
 "FizzBuzz"))
 nl))
 (1to 100)))
answered Aug 21, 2024 at 23:06
\$\endgroup\$
1
\$\begingroup\$

Boo, 114 bytes

for i in range(1,101):
 if i%15==0:print'FizzBuzz'
 elif i%5==0:print'Buzz'
 elif i%3==0:print'Fizz'
 else:print i

Try it online!

answered May 13, 2022 at 1:25
\$\endgroup\$
1
\$\begingroup\$

BrainChild, 97 bytes

include*;var p=print;while(int i++<100){if!(i%3)p("Fizz")if!(i%5)p("Buzz")if i%3&&i%5p(i)p("\n")}

Readable

include io.bc;
int i = 0;
while(i<100){
 i++;
 if (!(i%3))
 print("Fizz")
 if (!(i%5))
 print("Buzz")
 if (i%3 && i%5)
 print(i)
 print("\n")
}

Try It Online!

answered Nov 4, 2024 at 4:18
\$\endgroup\$
1
\$\begingroup\$

AWK, 56 bytes

{for(;i++<1ドル;)print i%3?i%5?i:y="Buzz":i%5?x="Fizz":x y}

To test:

awk '{for(;i++<1ドル;)print i%3?i%5?i:y="Buzz":i%5?x="Fizz":x y}' <<< 100
answered Nov 26, 2024 at 16:42
\$\endgroup\$
1
\$\begingroup\$

Hatchback, 256 bytes

0 1 3 0 2 5 0 4 1 0 5 100 0 9 70 0 10 105 0 8 122 0 12 66 0 13 117 0 14 10 2 0 4 10 7 0 15 7 1 6 7 65281 50 0 3 1 13 9 13 10 13 8 13 8 10 7 0 15 7 2 6 7 65281 71 13 12 13 13 13 8 13 8 0 65281 78 6 3 65281 77 12 0 13 14 10 6 0 9 6 5 0 3 0 6 6 65281 26 65535

this is super not optimized. I could probably make it better but this language is like super hard to understand

ungolfed and explained: (not valid code)

 | 0x0 is the incrementer
 | for clarification, the address 0xFF01 is used to increment
 | through instructions in the interpreter. when setting that
 | address, you have to set the number back by ~4 (depending on
 | what command you use) because of the interpreter skipping
 | a certain amount of times so it doesn't accidentally run
 | arguments like a command
0 1 3 | set 0x1 to 3 (mod 3)
0 2 5 | set 0x2 to 5 (mod 5)
0 4 1 | set 0x4 to 1 (increment)
0 5 100 | set 0x5 to 100 (max)
0 9 70 | set 0x9 to 70 (letter F)
0 10 105 | set 0xA to 105 (letter i)
0 8 122 | set 0x8 to 122 (letter z)
0 12 66 | set 0xC to 66 (letter B)
0 13 117 | set 0xD to 117 (letter u)
0 14 10 | set 0xE to 10 (newline)
 | start of loop...
2 0 4 | increment 0x0
10 7 0 | copy 0x0 to 0x7
15 7 1 | modulo 0x7 by 3
6 7 65281 50 | if 0x7 != 0, set 0xFF01 to 50 (jump to instruction). else...
0 3 1 | set 0x3 to 1 (so it knows not to print the number)
13 9 | inline print F
13 10 | ...i
13 8 | ...z
13 8 | ...z
10 7 0 | copy 0x0 to 0x7 again
15 7 2 | modulo 0x7 by 5
6 7 65281 71 | if 0x7 != 0, set 0xFF01 to 71. else...
13 12 | inline print B
13 13 | ...u
13 8 | ...z
13 8 | ...z
0 65281 78 | set 0xFF01 to 78 to skip printing the number
6 3 65281 77 | if 0x3 == 1, set 0xFF01 to 77. else...
12 0 | inline print 0x0
13 14 | print newline
10 6 0 | copy 0x0 to 0x6
9 6 5 | set 0x6 to the boolean result of (0x6 < 100) aka (0x6 < 0x5)
0 3 0 | set 0x3 to 0
6 6 65281 26 | if 0x6 != 0, then jump to the start of the loop.
65535 | end of program
answered Feb 6 at 17:55
\$\endgroup\$
1
\$\begingroup\$

Jalapeño, 32 bytes

1..e2↦{4%{23,5↭x{¬*}{2↻′)^FxXZa‚β−"wJ|I0L−

Explained

1..e2↦{4%{23,5↭x{¬*}{2↻′)^FxXZa‚β−"wJ|I0L−
1..e2 # range of 1 to 100
 ↦{4 # mapped via the next 4 links
 %{23,5 # the value modulo both 3 and 5
 ↭x # Zipping by
 {¬*} # Logical not of left, repeating right
 {2↻′)^FxXZa‚β−"w # The literal string "Fizz Buzz" split by spaces
 J # Joined, giving either ""|"Fizz"|"Buzz"|"FizzBuzz"
 |I0 # Logical or with the input number
 L− # Joined by newlines

Hex-Dump of Bytecode

 0 1 2 3 4 5 6 7 8 9 A B C D E F
0000: 31 2e 3b d0 c8 54 c6 33 29 35 cc c4 58 52 c5 c6 
0010: ff 71 07 55 04 7f 89 27 a6 48 20 18 14 57 90 17 

Try it Online!

answered Feb 12 at 3:14
\$\endgroup\$
1
\$\begingroup\$

SAKO, 176 bytes

CALKOWITE:I
*1)T=MOD(I,5)
GDYMOD(I,3)=0:3,INACZEJ4
3)TEKST
Fizz
GDYT=0:5,INACZEJ7
4)GDYT=0:5,INACZEJ6
5)TEKST
Buzz
SKOCZDO7
6)DRUKUJ(0):I
7)LINIA
POWTORZ:I=1(1)100
STOP1
KONIEC

I believe it's possible to shorten it more, but I don't see a way to do it.

answered Mar 14 at 15:42
\$\endgroup\$
1
\$\begingroup\$

AutoHotkey (v2), 88 bytes

Very straightforward ternary operations.

loop 100
f:=mod(n:=a_index,5),o.=(mod(n,3)?f?n:"Buzz":f?"Fizz":"FizzBuzz") "`n"
msgbox o
answered Sep 22 at 7:07
\$\endgroup\$
0
\$\begingroup\$

Python 2, 72 bytes

for x in range(100):print('Fizz'*(x%3>1)+'Buzz'*(x%5>3)or str(x+1))+'\n'

Not as clever as feersum's solution, but it avoids casting exec magic.

EDIT: with just two more parentheses, it works in Python 3 AND Python 2:

for x in range(100):print(('Fizz'*(x%3>1)+'Buzz'*(x%5>3)or str(x+1))+'\n')
answered Nov 2, 2015 at 22:59
\$\endgroup\$
1
  • \$\begingroup\$ even simpler, supress +'\n' and some parenbthesis : for x in range(100):print('Fizz'*(x%3>1)+'Buzz'*(x%5>3)or x+1) so 63 bytes Pthon 3 \$\endgroup\$ Commented Sep 2, 2021 at 19:53
0
\$\begingroup\$

APL, (削除) 56 (削除ここまで) 50 bytes

⊣{1+⍵⊣⎕←∊2↑((0=3 5|⍵)/'Fizz' 'Buzz'),''(⍕⍵)}⍣100⊢1

Note: The very first should suppress output in GNU APL. Replace it with to get correct results in Dyalog, etc, or with portable assignment to some variable X← adding one byte.

A+, 51 bytes

(x←100)do↓⊃2↑((0=3 5|1+x)/4⊂'FizzBuzz'),⌽2↑<1↓⍕1+x;
answered Nov 8, 2015 at 9:35
\$\endgroup\$
3
  • \$\begingroup\$ These seem quite different, so why not put them in different answers? \$\endgroup\$ Commented Nov 9, 2015 at 7:47
  • \$\begingroup\$ While I wouldn't call A+ a "trivial variant," it's a direct derivative of APL and I think any solution in one would translate to similar byte count in another. Also, I just updated it making the answers work exactly the same way. \$\endgroup\$ Commented Nov 9, 2015 at 9:22
  • \$\begingroup\$ The APL solution goes to 101 instead of stopping at 100. \$\endgroup\$ Commented Dec 6, 2022 at 15:12
0
\$\begingroup\$

Javascript ES6, 77 chars

"\n".repeat(100).replace(/(?=\n)/g,(m,i)=>(++i%3?m:"Fizz")+(i%5?m:"Buzz")||i)

Test:

"\n".repeat(100).replace(/(?=\n)/g,(m,i)=>(++i%3?m:"Fizz")+(i%5?m:"Buzz")||i) == document.querySelector("pre").textContent
answered Dec 13, 2015 at 21:32
\$\endgroup\$
4
  • \$\begingroup\$ Here's my ES6 attempt, with parts stolen from yours (89 chars): "0".repeat(99).split(0).map((m,i)=>{return(++i%3?m:"Fizz")+(i%5?m:"Buzz")||i}).join("\n") \$\endgroup\$ Commented Jan 7, 2016 at 6:48
  • \$\begingroup\$ @starbeamrainbowlabs, why do you use {return ...} instead of expression? \$\endgroup\$ Commented Jan 7, 2016 at 10:21
  • \$\begingroup\$ Because I couldn't get the expression to work :( \$\endgroup\$ Commented Jan 7, 2016 at 16:20
  • \$\begingroup\$ Save a byte by using template strings + literal newline at front. \$\endgroup\$ Commented Jan 29, 2016 at 0:34
0
\$\begingroup\$

///, 229 bytes

/x/Buzz//b/
x//f/
Fizz/1
2f
4bf
7
8fb
11f
13
14fx
16
17f
19bf
22
23fb
26f
28
29fx
31
32f
34bf
37
38fb
41f
43
44fx
46
47f
49bf
52
53fb
56f
58
59fi
61
62f
64bf
67
68fb
71f
73
74fx
76
77f
79bf
82
83fb
86f
88
89fx
91
92f
94bf
97
98fb
answered Jun 3, 2016 at 14:17
\$\endgroup\$
3
  • \$\begingroup\$ Out-golfed \$\endgroup\$ Commented May 15, 2017 at 2:58
  • \$\begingroup\$ @Challenger5 Well done. \$\endgroup\$ Commented May 15, 2017 at 2:59
  • \$\begingroup\$ @LeakyNum I have A CJam script that finds common substrings in the input. It's useful for /// golfing. \$\endgroup\$ Commented May 15, 2017 at 5:55
0
\$\begingroup\$

JavaScript (using external library) (90 bytes)

x=>_.Range(1,100).Select(x=>x%3==0?(x%5==0?"FizzBuzz":"Fizz"):x%5==0?"Buzz":x).WriteLine()

Link to library: https://github.com/mvegh1/Enumerable/

Code explanation: Creates a range starting at 1 and extending 100 elements. Select maps the item according to the predicate. First check if divisible by 3, if so check if divisible by 5. If so, select "FizzBuzz", else select "Fizz". Otherwise,check if divisible by 5. If so, select "Buzz", else just select the number. WriteLine is built into the library, and it writes each element on its own line

enter image description here

answered Jul 25, 2016 at 15:55
\$\endgroup\$
0
\$\begingroup\$

DUP, 76 bytes

[$3ドル/%$[]['F,'i,'z,'z,]?5円/%$[]['B,'u,'z,'z,]?*[$.][]?10,]c:0[100ドル<][1+c;!]#

Explanation of program flow, code blocks:

DUP has two default truth values: -1 (true, all bits set) and 0 (false, no bits set). For conditional evaluations every nonzero value is accepted as true, comparisons themselves lead to either -1 or 0.

DUP has two conditional expressions, if-then-else and a while loop:

[execute if not false][execute if false]?. E.g. 1['t,]['f,]? prints t to STDOUT, because 1 is not false.

[condition][execute while not false]#. E.g. 5[0ドル>][$.1-]# prints the numbers 5,4,3,2,1 to STDOUT. The condition block tests the top stack value if it’s greater than 0, the execute block prints the number and decrements it.

The condition that’s checked is always the topmost stack element, which gets popped off the stack during the check.

[
 $3ドル/%$ {dup,dup,push 3, moddiv, pop, dup}
 [] {if condition true do nothing}
 ['F,'i,'z,'z,]? {if condition false print Fizz}
 5円/%$ {swap, push 5, moddiv, pop, dup}
 [] {if condition true do nothing}
 ['B,'u,'z,'z,]? {if condition false print Buzz}
 * {mul}
 [$.] {if condition true dup, print to STDOUT}
 []? {if condition false do nothing}
 10, {push 10, print char to STDOUT (newline)}
]c: {define function c}
0 {push 0}
[100ドル<] {while dup < push 100 true}
 [1+c;!]# {do push 1, add, execute function c}

Step by step:

instruction stack
0 0
[
$ 0,0
100 0,0,100
< 0,-1
] 0
[
1 0,1
+ 1 increment counter
c; 1,0 0=start address of function c
! execute c
[
$3ドル 1,1,1,3
/ 1,1,1,0 mod,div operator (n mod 3, n div 3)
% 1,1,1 /% → mod
$ 1,1,1,1 result of n%3 used as flag for later check
[] 1,1,1 condition true→do nothing
['F,'i,'z,'z,]? skipped
\ 1,1,1 swap top and 2nd stack elements
5 1,1,1,5
/ 1,1,1,0 mod,div operator
% 1,1,1 /% → mod
$ 1,1,1,1 n%5 flag
[] 1,1,1 condition true → do nothing
['B,'u,'z,'z,]? skipped
* 1,1 multiply %3 and %5 flags, result is only >0
 if neither %3 nor %5 are 0.
[ 1 if condition (flag)>0
 $ 1,1 dup
 .] 1 print number to STDOUT: '1'
[]? skipped
back to while loop
[
$ 1,1
100 1,1,100
< 1,-1
] 1
[
1 1,1
+ 2 increment counter
c; 2,0 0=start address of function c
! execute c
...

A full description of all operators and program flow can be found at my GitHub repository, together wtih my Julia interpreter of DUP.

An online Javascript implementation showing useful debug information can be found here.

A rather terse introduction can be found on the esolangs.org DUP page.

answered Dec 23, 2016 at 22:01
\$\endgroup\$
0
\$\begingroup\$

S.I.L.O.S, 141 bytes

lbla
a+1
c=1-(a%3)*(a%5)
if c b
printIntNoLine a
lblb
c=(a%3)
if c d
print Fizz
lbld
c=(a%5)
if c c
print Buzz
lblc
printLine 
b=100-a
if b a

Try it online!

Unfortunately SILOS is incredibly verbose, and an interpreter bug cost me a few extra bytes, but I think SILOS is "superior" only to scratch in this challenge.

answered May 14, 2017 at 15:12
\$\endgroup\$
1
...
11 12 13
14
15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.