1, 2, Fizz, 4, Buzz!
The task
Output the first 100 elements of the infamous FizzBuzz sequence.
How?
The FizzBuzz sequence is the sequence of decimal integers from 1 to 100 inclusive, but:
 If the integer is divisible both by 3 and 5, output the string
FizzBuzz
 Else, if the integer is divisible by 3, output the string
Fizz
instead  Else, if the integer is divisible by 5, output the string
Buzz
instead  Else, output the integer itself
Output
The output will be a list of these elements separated by either a space (U+0020
) or a newline (U+000A
).
Here is a sample output with newline separation:
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
Rules
 Your code may not print anything to STDERR. Warnings are fine.
 This is codegolf, so lowest bytecount in each language is the winner.
C (gcc), 113 Bytes ``` i;mai …
5mo ago
goruby, 1 byte ```ruby f …
5mo ago
[Shakespeare Programming Langu …
5mo ago
[RoadLang], 340 bytes ` …
5mo ago
C (gcc), 108 bytes ```c h, …
5mo ago
Japt `R`, 28 bytes Lõ@ …
5mo ago
[JavaScript (Node.js)], 64 byt …
5mo ago
Canvas, 24 bytes zz＋¹┘％！＊ …
5mo ago
Vyxal, `jM`, 18 bytes ``` …
5mo ago
9 answers
C (gcc), 113 Bytes
i;main(){while(i++<100){char*h[]={"%d "," "},**p=h;i%3(*p++="Fizz%2$s");i%5(*p="Buzz ");printf(*h,i,h[1]);}}
This compiles with several warnings, but no errors.
Here's an ungolfed version with explanations:
/* the following include is omitted; while using printf
without including it is not conforming to the current
C standard, with gcc it only generates a warning
and works flawlessly. Note that omission was valid K&R C */
#include <stdio.h>
/* Declare a global int variable. The golfed code omits the
type because of the old implicitint rule, which only
generates a warning also in modern gcc. Also note that
global variables without initializer are zeroinitialized;
this is still defined behaviour today. In this ungolfed
code I've added the implied initializer for clarity. */
int i=0;
/* The main function. Again, the golfed code makes use of the
old implicit int rule. */
int main()
{
/* loop up to 100; since we increment before entering the
loop body, the first number in the loop is 1. */
while(i++<100)
{
/* In this array of two strings, the first will be used as
format string to a printf later, while the second will
be the third argument for the same printf. As is, the
format string will tell printf to format the second
argument (which will be i) as number, followed by a space.
The third argument, a singlespace string, is ignored
in that case. */
char *h[] = { "%d ", " " };
/* This second variable (which in the golfed version is
declared in the same declaration as h) points to the first
entry of h. It is used to change the entries of h, and
it is separate because pointer arithmetic is used to
modify different strings depending on the condition. */
char **p = h;
/* This is basically an ifnot statement. If i%3 is not
nonzero (that is, if i is divisible by 3), this statement
replaces the format string with one that prints "Fizz"
followed by the content of the third argument of printf
as string, which is the second string in h. At this
point it contains just a space. Also, when replacing the
format string, the pointer p is incremented, so it then
points to the second element of h. */
i%3  (*p++ = "Fizz%2$s");
/* This ifindisguise handles divisibility by 5. It stores
a pointer to "Buzz " into whatever p points to. If i
is not divisible by 3, this still is the format string,
so if instructs the following printf to just print "Buzz "
and ignore any further arguments. Otherwise, p points
to the final string argument, so that after the "Fizz"
it prints "Buzz " instead of just a space. */
i%5  (*p = "Buzz ");
/* This finally is the printf statement talked about
in the previous comments. Note that *h is equivalent
to h[0] */
printf(*h,i,h[1]);
}
}
1 comment
Nice solution since it's quite straightforward, +1. I managed 108 bytes with same compiler settings (default gcc) but a much more obscure solution here.
goruby, 1 byte
f
Okay, so that's a bit unfair. 😂 The definition of f
from golf_prelude.rb
(which is what goruby embeds) is quite golfy in itself:
def f(m = 100)
1.upto(m){nputs'FizzBuzz
'[i=n**4%15,i+13]n}
end
Substituting m
with 100 directly gives us the Ruby version, which weighs in at 51 bytes:
1.upto(100){nputs'FizzBuzz
'[i=n**4%15,i+13]n}
0 comments
Shakespeare Programming Language, 11232 bytes
My last attempt was nearing the 20000 byte zone, because it didn't use the stack at all.
a.Ajax,.Puck,.Ford,.Act I:.Scene I:.[Enter Ajax and Puck]Ajax:You is twice the sum ofa cat a big big cat.Puck:You is the sum oftwice the sum ofthe cube ofa big big cat a big pig a big pig.Scene V:.[Exeunt][Enter Ajax and Puck]Puck:Remember you!Remember you!Remember the sum ofthe sum ofyou a big big pig a pig!Remember the sum ofthe cube ofa big big cat a big cat!Remember me!Remember you!Remember you!Remember the sum ofthe sum ofyou a big big big big pig a pig!Remember the sum oftwice the sum ofa big cat a cat the cube ofa big big cat!Remember me!Remember me!Remember me!Remember you!Remember you!Remember the sum ofthe sum ofyou a big big big big pig a pig!Remember the sum oftwice the sum ofa big cat a cat the cube ofa big big cat!Remember me!Remember you!Remember you!Remember the sum ofthe sum ofyou a big big pig a pig!Remember the sum ofthe cube ofa big big cat a big cat!Remember me!Remember me!Remember you!Remember you!Remember the sum ofthe sum ofyou a big big big big pig a pig!Remember the sum oftwice the sum ofa big cat a cat the cube ofa big big cat!Remember me!Remember me!Remember me!Remember you!Remember you!Remember the sum ofthe sum ofyou a big big pig a pig!Remember the sum ofthe cube ofa big big cat a big cat!Remember you!Remember you!Remember the sum ofthe sum ofyou a big big big big pig a pig!Remember the sum oftwice the sum ofa big cat a cat the cube ofa big big cat!Remember me!Remember me!Remember me!Remember you!Remember you!Remember the sum ofthe sum ofyou a big big big big pig a pig!Remember the sum oftwice the sum ofa big cat a cat the cube ofa big big cat!Remember me!Remember me![Exit Ajax][Enter Ford]Puck:You is the sum ofyou a cat!Be you worse twice the sum ofa big cat a cat?If soLet usScene V![Exit Ford][Enter Ajax]Puck:Remember you!Remember you!Remember the sum ofthe sum ofyou a big big pig a pig!Remember the sum ofthe cube ofa big big cat a big cat!Remember me!Remember you!Remember you!Remember the sum ofthe sum ofyou a big big big big pig a pig!Remember the sum oftwice the sum ofa big cat a cat the cube ofa big big cat!Remember me!Remember me!Remember me!Remember you!Remember you!Remember the sum ofthe sum ofyou a big big big big pig a pig!Remember the sum oftwice the sum ofa big cat a cat the cube ofa big big cat!Remember me!Remember you!Remember you!Remember the sum ofthe sum ofyou a big big pig a pig!Remember the sum ofthe cube ofa big big cat a big cat!Remember me!Remember me!Remember you!Remember you!Remember the sum ofthe sum ofyou a big big big big pig a pig!Remember the sum oftwice the sum ofa big cat a cat the cube ofa big big cat!Remember me!Remember me!Puck:You cat!Open heart!Recall!Speak thy!You big cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You big big cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You is the sum ofa big big big cat a pig!Open heart!Recall!Speak thy!You big big big cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You cat!Open heart!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You is the sum ofthe sum ofa big cat a cat you!Open heart!Recall!Speak thy!You is the sum ofyou a big big cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You big big big big cat!Open heart!Recall!Speak thy!You is the sum ofa big big big big cat a cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You cat!Open heart!You is the sum ofa big big big cat a cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You big cat!Open heart!Open heart!Recall!Speak thy!You big cat!Open heart!You is the sum ofyou a cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You big cat!Open heart!You is twice the sum ofyou a cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You is twice the sum ofyou a big big cat!Open heart!Recall!Speak thy!You big cat!Open heart!You is the sum ofa big big big cat a cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You is the sum ofa big cat a cat!Open heart!You cat!Open heart!Recall!Speak thy!You big big big big big cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You is twice the sum ofa big big big big cat a cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You is the sum oftwice twice the sum ofa big big big cat a cat a cat!Open heart!Recall!Speak thy!You is twice the sum oftwice the sum ofa big big big cat a cat a cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You big big cat!Open heart!You cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You big big cat!Open heart!You is the sum ofyou a pig!Open heart!Recall!Speak thy!You big big cat!Open heart!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You big big cat!Open heart!You is the sum ofyou a big cat!Open heart!Recall!Speak thy!You big big cat!Open heart!You is the sum oftwice you a pig!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You is the square ofthe sum ofa big big big cat a pig!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You is the sum ofa big big cat a cat!Open heart!You big cat!Open heart!Recall!Speak thy!You is the sum oftwice the sum ofthe factorial ofa big big cat a big cat a cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You is twice twice the sum ofyou a big big cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You is the sum ofa big big cat a cat!Open heart!You big big big cat!Open heart!Recall!Speak thy!You is the sum ofa big big cat a cat!Open heart!You is the sum ofyou a big big cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You is twice the sum ofa big cat a cat!Open heart!You cat!Open heart!Recall!Speak thy!You is the sum ofthe cube ofa big big cat a big pig!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You is the cube ofa big big cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You is the sum ofthe sum ofthe cube ofa big big cat a big cat a cat!Open heart!Recall!Speak thy!You is the sum ofthe cube ofa big big cat a big big cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You is the sum ofa big big big cat a pig!Open heart!You cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You is the sum oftwice the square oftwice the sum ofa big cat a cat a cat!Open heart!Recall!Speak thy!You is the sum oftwice the square oftwice the sum ofa big cat a cat a big cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You is the sum oftwice the square oftwice the sum ofa big cat a cat a big big cat!Open heart!Recall!Speak thy!You is the sum ofa big big big cat a pig!Open heart!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You is the sum ofa big big big cat a pig!Open heart!You is the sum ofyou a big cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You big big big cat!Open heart!You big cat!Open heart!Recall!Speak thy!You big big big cat!Open heart!You is the sum ofa big cat a cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You big big big cat!Open heart!You is the sum ofyou a big pig!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You big big big cat!Open heart!Open heart!Recall!Speak thy!You big big big cat!Open heart!You is the sum ofyou a cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You is the sum ofa big big big cat a cat!Open heart!You cat!Open heart!Recall!Speak thy!You is the sum ofa big big big cat a cat!Open heart!You big cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You is the sum ofa big big big cat a cat!Open heart!You big big cat!Open heart!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!Recall!Speak thy!You is the sum ofa big big big cat a cat!Open heart!You is the sum ofyou a big pig!Open heart!Recall!Speak thy!You is the sum ofthe square ofyou a big pig!Open heart!Ajax:You is the sum oftwice the sum ofa big big cat a cat a cat!Scene L:.Puck:Recall!Speak thy!Ajax:You is the sum ofyou a pig!Be you nicer a cat?If soLet usScene L!
Works by adding the FizzBuzz line breaks and words to the stack (in reverse) for the first 90, adds the last 10 lines, then goes through and prints all the numbers and words by recalling the stack at specific times. SPL doesn't support division so this is the shortest method I could think of, short of subtracting numbers and checking if they... equal... zero...
Oh god, I've gotta go golf more. I'm leaving this here as a mark that I've done something, though.
0 comments
JavaScript (Node.js), 64 bytes
for(n=0;101>++n;)console.log([['Fizz'][n%3]]+[['Buzz'][n%5]]n)
0 comments
C (gcc), 108 bytes
*h,i;main(){for(;i++<100;){char s[]="%dFizzBuzz ",b=i%5;h=s+2;printf(s+(i%3?b?*h=32,0:6:b?h[1]=32,2:2),i);}}
Godbolt. Works on clang too. Contains some serious abuse of all that is holy: gcc extensions, misaligned writes, endianess, poorlydefined behavior...
Newline instead of space, 109 bytes:
*h,i;main(){for(;i++<100;){char s[]="%dFizzBuzz\n",b=i%5;h=s+2;printf(s+(i%3?b?*h=10,0:6:b?h[1]=10,2:2),i);}}
I'm a rookie at code golf so this could probably be improved a lot.
Explanation:
The whole code is based on a local string s
which is refreshed at each lap of the loop.
Basically the whole expression is a big ifelse written with ?:, designed to return a pointer offset to the string as result.
 In case a normal number should be printed, a space and null terminator is inserted after
%d
.  In case
FizzBuzz
should be printed, the array offset is increased with pointer arithmetic to start from Fizz.  In case only 'Fizz' should be printed, a space + null terminator is inserted after
Fizz
.  In case only 'Buzz' should be printed, the array offset is increased with pointer arithmetic.
Space + null terminator is written by a lvalue access of int
through h
to the string, which is both a strict aliasing violation, a misaligned access and endianess reliance all at once. The raw data of 0x00000020
is written into the string, little endian meaning that 0x20 ends up in ls byte and then a 0x00 byte after that, forming a null terminator.
printf
is abused by getting passed an additional parameter i
whether or not the format string contains any conversion specifier.
gcc extensions abused:
 implicit int

main()
form and noreturn 0
in case of C90.  no
#include
 incompatible pointer conversion from
char*
toint*
.  Dodging strict pointer aliasing
0 comments
RoadLang, 340 bytes
wagwan my slime
x is 0
rip dat bong till x bigger den 99 n dat
x is x n 1
ayy bossman (x leftova 15) be 0 init bruv
man say"FizzBuzz"
yeah init bruv
ayy bossman (x leftova 5) be 0 init bruv
man say"Buzz"
yeah init bruv
ayy bossman (x leftova 3) be 0 init bruv
man say"Fizz"
yeah init bruv
man say x
yeah
yeah
yeah
mmm
chat wit u later fam
Make sure you rip dat bong dis christmas eve!
Here's a more slimy answer:
wagwan my slime
I is nuttin
rip dat bong till I bigger den 99 n dat
I is I n bar
ayy bossman (I leftova (beehive x bender ova bice) ) be 0 init bruv
man say "FizzBuzz"
yeah init bruv
ayy bossman (I leftova beehive) be nuttin init bruv
man say "Buzz"
yeah init bruv
ayy bossman (I leftova bender ova bice) be 0 init bruv
man say "Fizz"
yeah init bruv
man say I
yeah
yeah
yeah
mmm
chat wit u later fam
1 comment
this language is fantastic
Vyxal, jM
, 18 bytes
Ĥƛ3œıƆĿ*n5œıŧĤ*+n⟇
Explained
Ĥƛ3œıƆĿ*n5œıŧĤ*+n⟇
Ĥ # Push the number 100
ƛ # Start a lambda map doing the following over the range [1, 100]: (it would usually map over [0,99] but the M flag makes the lambda increase the start and end of that range)
3œ # Find the divisibility of the argument by 3 AND
ıƆĿ # Push the compressed string "Fizz" AND
* # Multiply the two together THEN
n5œ # Find the divisibility of the argument by 5 AND
ıŧĤ # Push the compressed string "Buzz" AND
* # Multiply the two together THEN
+ # Add the two multiplied strings together THEN
n⟇ # Shortcircuit OR the string and the argument.
# The `j` flag automatically joins with newlines
0 comments
Canvas, 24 bytes
zz＋¹┘％！＊
‾U｛ŗ３Fi⁸５Bu⁸＋ｎＯ
Explanation (ASCIIfied for better monospacing):
zz+¹┘%!* Helper function ⁸; Expects stack to be [modulo, string]
zz+ append "zz" to the string
¹ push the current loop index
┘ retrieve the modulo
% calculate the modulo
! negate (i.e. isdivisible)
* repeat the string vertically that many times
‾U{ŗ3Fi⁸5Bu⁸+nO Main program
‾U{ Repeat 100 times, pushing index & writing it to ¹
ŗ stringify the pushed index
3Fi⁸ invoke ⁸ on [3; "Fi"]
5Bu⁸ invoke ⁸ on [5; "Bu"]
+ join the two results
n overlap that over the index; this works as the maximum index, 100, is less than 4 characters
O output that
7 comments
I'm pretty sure U+0020 is the space, and U+000A is the newline. BTW, what exactly does "must not produce an error from start to finish" mean? In particular, do compiler warnings count as errors in this context? — celtschk 5 months ago
@celtschk fixed, thanks — Dion 5 months ago
Now I'm sad. SPL relies on STDERR to be golfed effectively, heh.Time to double the length of my program... — Corsaka 5 months ago
@corsaka if you think it is acceptable to change the rules at this point, then I can edit the post so that programs may not HALT on errors — Dion 5 months ago
Wait, are warnings considered STDERR? If not, that solves the issue. If yes, then the top answer is also incorrect. — Corsaka 5 months ago