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 code-golf, so lowest byte-count in each language is the winner.
C (gcc), 113 Bytes ``` i;mai …
4y ago
[RoadLang], 340 bytes ` …
4y ago
goruby, 1 byte ```ruby f …
4y ago
[JavaScript (Node.js)], 64 byt …
4y ago
[Shakespeare Programming Langu …
4y ago
C (gcc), 108 bytes ```c h, …
4y ago
Japt `-R`, 28 bytes Lõ@ …
4y ago
[AWK], 72 bytes BEGIN{f …
3y ago
Japt `-R`, 27 bytes Lõ@ …
3y ago
Canvas, 24 bytes zz+¹┘%!* …
4y ago
Vyxal `Hj`, 10 bytes …
3y ago
[C (gcc)], 103 bytes Using …
3y ago
[shortC], 95 93 91 bytes …
3y ago
[Haskell], 110 bytes …
3y ago
[Python 3], 64 62 bytes …
3y ago
[Lua], 126 118 bytes …
3y ago
[Julia 1.0], 79 bytes …
3y ago
Rockstar, 138 135 133 bytes …
3y ago
Sclipting, (UTF-16) 62 bytes …
3y ago
[AWK], 62 61 60 56 bytes …
6mo ago
[PHP], 114 bytes Ph …
3y ago
21 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 implicit-int rule, which only
generates a warning also in modern gcc. Also note that
global variables without initializer are zero-initialized;
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 single-space 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 if-not 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 if-in-disguise 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]);
}
}
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
JavaScript (Node.js), 64 bytes
for(n=0;101>++n;)console.log([['Fizz'][n%3]]+[['Buzz'][n%5]]||n)
0 comment threads
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){|n|puts'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){|n|puts'FizzBuzz
'[i=n**4%-15,i+13]||n}
0 comment threads
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.
1 comment thread
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, poorly-defined 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 if-else 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 comment threads
Japt -R
, 27 bytes
Lõ@"FiBu"ò úz4 ËpXv°EÑÄìªX
Lõ@"FiBu"ò úz4 ËpXv°EÑÄìªX
L :100
õ :Range [1,L]
@ :Map each X
"FiBu" : Literal string
ò : Partitions of length 2
úz4 : Right pad each with "z" to length 4
Ë : Map each element at 0-based index E
p : Repeat
Xv : Test X for divisibility by (result will be 1 or 0)
°E : Prefix increment E
Ñ : Multiply by 2
Ä : Add 1
à : End map
¬ : Join
ªX : Logical OR with X
:Implicit output, joined with newlines
0 comment threads
Canvas, 24 bytes
zz+¹┘%!*
‾U{ŗ3Fi⁸5Bu⁸+nO
Explanation (ASCII-fied 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. is-divisible)
* 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
0 comment threads
Vyxal Hj
, 10 bytes
ƛ₍₃₅kF½*∑∴
Vyxal has gotten a whole lot better since first posting this.
Explained
Very simply, this is: for each item in the range [1, 100]
, create the list [item % 3 == 0, item % 5 == 0]
, multiply that by ["Fizz", "Buzz"]
, sum that and get the maximum of the number and the summed list.
0 comment threads
AWK, 72 bytes
BEGIN{for(i=1;i<101;i++){s="";i%3||s="Fizz";i%5||s=s"Buzz";print s?s:i}}
0 comment threads
Haskell, 110 bytes
main=mapM(\n->putStrLn$case(rem n 3,rem n 5)of(0,0)->"FizzBuzz";(0,_)->"Fizz";(_,0)->"Buzz";_->show n)[1..100]
0 comment threads
Rockstar, 138 135 133 bytes
F takes I&S
let M be N/I
turn up M
if N-I*M
S's""
return S
N's0
while N-100
let N be+1
say F taking 3,"Fizz"+F taking 5,"Buzz" or N
Try it here (Code will need to be pasted in)
0 comment threads
Julia 1.0, 79 bytes
println.(i%15<1 ? "FizzBuzz" : i%3<1 ? "Fizz" : i%5<1 ? "Buzz" : i for i=1:100)
0 comment threads
Lua, 126 118 bytes
p=print for i=1,100 do if i%15==0 then p"FizzBuzz"elseif i%3==0 then p"Fizz"elseif i%5==0 then p"Buzz"else p(i)end end
0 comment threads
AWK, 62 61 60 56 bytes
{for(;i++<$1;)print i%3?i%5?i:y="Buzz":i%5?x="Fizz":x y}
{for(;i++<$0;)print i%15?i%5?i%3?i:"Fizz":"Buzz":"FizzBuzz"}
{for(;i++<$0;x=""){i%3||x="Fizz";i%5||x=x"Buzz";print x?x:i}}
{for(;i++<$0;){i%3?x="":x="Fizz";i%5?J:x=x"Buzz";print x?x:i}}
This code relies on passing the value 100 (or any number desired) to process. We take advantage of string concatenation and ternary operators.
A self-contained version:
BEGIN{for(;i++<100;x=""){i%3||x="Fizz";i%5||x=x"Buzz";print x?x:i}}
1 comment thread