[ create a new paste ] login | about

Recent implementations of FizzBuzz, in:
[ C | C++ | Haskell | Lua | PHP | Perl | Python | Ruby ]

C:
pasted on Mar 21:
#include <stdio.h>
#define like (!(
#define beers )){
#define bought !=
#define hey  int
#define dude ((
#define allright main (void
#define when for(
#define spilled  =
#define man ;
#define rock ++
#define say printf(
#define drank %
#define ok );}
#define mugs )&&(
#define lol );
#define so ){
#define omg }
#define wtf return 0

hey you man
hey allright so
when you spilled 1 man you bought 101 man you rock so
if like you drank 3 beers say "Fizz" ok
if like you drank 5 beers say "Buzz" ok
if dude you drank 3 mugs you drank 5 beers
say "%i", you lol
omg say "\n" lol
omg wtf man
omg
view (30 lines, 100 lines of output)
pasted on Mar 20:
#include <stdio.h>
int main(void)
{
	int i;

	for (i = 1; i <= 100; i++) {
		if (i % 15 == 0) {
			printf("FizzBuzz\n");
		}

		else if (i % 3 == 0) {
			printf("Fizz\n");
		}

		else if (i % 5 == 0) {
			printf("Buzz\n");
		}

		else {
			printf("%d\n", i);
		}
	}
    return 0;
}
view (24 lines, 100 lines of output)


C++:
pasted on Mar 21:
#include <iostream>
#include <string>
using namespace std;
int main(){
int num1=0;
int num2=0;
string fizzer="";  
do{
num1++;
string fizzer="";  
if (num1%3==0){
    fizzer+="fizz";
    }
if (num1%5==0){
    fizzer+="buzz";
    }/*
if (num1%7==0){
    fizzer+="woof";
    }*/
if(fizzer.length() == 0){
cout << num1  << endl;
}

else{
cout << fizzer << endl;
}

}while (num1<100);
  

  return 0;
}
view (32 lines, 100 lines of output)
pasted on Jan 11:
#include <iostream>

int main() {
for (int i = 1; i <= 100; i++) {
    bool fizz = (i % 3) == 0;
    bool buzz = (i % 5) == 0;

    if (fizz) {
        std::cout << "Fizz";
    }

    if (buzz) {
        std::cout << "Buzz";
    }

    if (!fizz && !buzz) {
        std::cout << i;
    }

    std::cout << '\n';
}
return 0;
}
view (23 lines, 100 lines of output)


Haskell:
pasted on Mar 20:
1
2
3
4
5
6
7
8
fizz :: Int -> String
fizz n | n `mod` 15 == 0  = "FizzBuzz"
       | n `mod` 3  == 0  = "Fizz"
       | n `mod` 5  == 0  = "Buzz"
       | otherwise        = show n
 
main :: IO()
main = mapM_ putStrLn $ map fizz [1..100]
view (8 lines, 100 lines of output)
pasted on Dec 29:
1
2
3
4
5
6
7
  subst (i, a)
    | i `mod` 15 == 0 = putStrLn "FizzBuzz"
    | i `mod` 5 == 0 = putStrLn "Buzz"
    | i `mod` 3 == 0 = putStrLn "Fizz"
    | otherwise = a
  makePrint i = (i, putStrLn $ show i)
  main = sequence_ $ map (subst . makePrint) [1..100]
view (7 lines, 100 lines of output)


Lua:
pasted on Mar 2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function fizzbuzz(n)
    if n%15 == 0 then
        print("fizzbuzz")
    elseif n%5 == 0 then
        print("buzz")
    elseif n%3 == 0 then
        print("fizz")
    else
        print("" .. n)
    end
end

for i=1,100,1 do
    fizzbuzz(i)
end
view (15 lines, 100 lines of output)
pasted on Feb 14:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function fizzbuzz(n)
    if n%15 == 0 then
        print("fizzbuzz")
    elseif n%5 == 0 then
        print("buzz")
    elseif n%3 == 0 then
        print("fizz")
    else
        print("" .. n)
    end
end

for i=1,100,1 do
    fizzbuzz(i)
end
view (15 lines, 100 lines of output)


PHP:
clambercy - pasted on Dec 17:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php

for ($i = 1; $i <= 100; $i++) {
    $out = '';
    if ($i % 3 == 0) {
        $out = "Fizz";
    } 
    if ($i % 5 == 0) {
        $out .= "Buzz";
    }
    
    echo ($out ? $out : $i) . PHP_EOL;
}


?>
view (16 lines, 100 lines of output)
clambercy - pasted on Dec 17:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php

for ($i = 1; $i <= 100; $i++) {
    $out = '';
    if ($i % 3 == 0) {
        $out = "Fizz";
    } 
    if ($i % 5 == 0) {
        $out .= "Buzz";
    }
    if ($out == '') {
        $out = $i;
    } 
    echo ($out ? $out : $i) . PHP_EOL;
}


?>
view (18 lines, 100 lines of output)


Perl:
pjvangemmeren - pasted on Oct 12:
1
 print+(Fizz)[$_%3].(Buzz)[$_%5]||$_,$/for 1..100
view (1 line, 100 lines of output)
pasted on Oct 7:
1
 print+(Fizz)[$_%3].(Buzz)[$_%5]||$_,$/for 1..100
view (1 line, 100 lines of output)


Python:
pasted on Feb 14:
1
2
3
4
5
for i in range(1,101):
    if i%15 == 0: print("fizzbuzz")
    elif i%3 == 0: print("fizz")
    elif i%5 == 0: print("buzz")
    else: print(i)
view (5 lines, 100 lines of output)
pasted on Jan 17:
1
2
3
4
5
6
7
8
9
for x in range(1,101):
    if x % 15 == 0:
        print "FizzBuzz" # Catch multiples of both first.
    elif x % 3 == 0:
        print "Fizz"
    elif x % 5 == 0:
        print "Buzz"
    else:
        print x
view (9 lines, 100 lines of output)


Ruby:
pasted on Mar 22:
1
2
3
4
5
6
7
8
9
10
11
(1..100).each do |n|
if n % 5 == 0 && n % 3 == 0
puts "FizzBuzz"
elsif n % 5 == 0
puts "Buzz"
elsif n % 3 == 0
puts "Fizz"
else
puts n
end 
end 
view (11 lines, 100 lines of output)
pasted on Mar 22:
1
2
3
4
5
6
7
8
9
10
11
(1..100).each do |i|
  if i % 5 == 0 and i % 3 == 0
    puts "FizzBuzz"
  elsif i % 5 == 0
    puts "Buzz"
  elsif i % 3 == 0
    puts "Fizz"
  else
    puts i 
  end 
end 
view (11 lines, 100 lines of output)