[ create a new paste ] login | about

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

C:
pasted on Jul 20:
1
2
3
4
5
6
7
8
9
10
11
#include<stdio.h>
#include<stdlib.h>
 
int fizz(int i){
  printf("%d\n\0fizz\n\0fizzbuzz\n"+!(i%3)*4+!(i%5)*14-!(i%15)*8, i);
  (fizz+((int(*)(int))exit-fizz)*(i/100))((i+1)%101);
}
 
int main(void){
  fizz(1);
}
view (11 lines, 100 lines of output)
pasted on Jun 30:
1
2
3
4
5
6
7
8
9
10
11
#include<stdio.h>
#include<stdlib.h>

int fizz(int i){
  printf("%d\n\0fizz\n\0fizzbuzz\n"+!(i%3)*4+!(i%5)*14-!(i%15)*8, i);
  (fizz+((int(*)(int))exit-fizz)*(i/100))((i+1)%101);
}

int main(void){
  fizz(1);
}
view (11 lines, 100 lines of output)


C++:
pasted on Jul 13:
1
2
3
4
5
6
7
8
9
10
#include "stdio.h"
int main(void) {
    int x;
    for(x=1;x<101;x++) {
        if (x%3==0) printf("Fizz");
        if (x%5==0) printf("Buzz");
        else if (x%3) printf("%d", x);
        printf("\n");
    }
}
view (10 lines, 100 lines of output)
pasted on Jul 4:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    
#include <iostream>
#include <string>
#include <sstream>

int main()
{
for(int i=0;i<100;i++)
{
    std::stringstream ss;
    if((i+1) % 3 == 0) ss<<"Fizz";
    if((i+1) % 5 == 0) ss<<"Buzz";
    if((int)strlen(ss.str().c_str()) == 0) ss<<i+1;
    std::cout<<ss.str()<<std::endl;
}
return 0;
}
view (17 lines, 100 lines of output)


Haskell:
pasted on Jul 15:
1
2
3
4
5
6
7
8
9
10
fizzBuzz :: (Integral a) => a -> String
fizzBuzz i
  | fizz && buzz = "FizzBuzz"
  | fizz = "Fizz"
  | buzz = "Buzz"
  | otherwise = show i
  where fizz = mod i 3 == 0
        buzz = mod i 5 == 0

main = mapM_ (putStrLn . fizzBuzz) [1..100]
view (10 lines, 100 lines of output)
pasted on May 13:
1
2
3
4
5
6
7
8
9
10
fizzBuzz :: (Integral a) => a -> String
fizzBuzz i
  | fizz && buzz = "FizzBuzz"
  | fizz = "Fizz"
  | buzz = "Buzz"
  | otherwise = show i
  where fizz = mod i 3 == 0
        buzz = mod i 5 == 0

main = mapM_ (putStrLn . fizzBuzz) [1..100]
view (10 lines, 100 lines of output)


Lua:
pasted on Apr 12:
1
2
3
4
5
6
7
8
9
10
11
for i = 1, 100 do
   if i % 3 == 0 and i % 5 == 0 then
      print "FizzBuzz"
   elseif i % 3 == 0 then
      print "Fizz"
   elseif i % 5 == 0 then
      print "Buzz"
   else
      print(i)
   end
end
view (11 lines, 100 lines of output)


PHP:
pasted on Jul 20:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
for($i=1; $i<=100; $i++) {
    $res= '';
    if(($i%3)===0){
        $res = 'Fizz';		
    }
    if(($i%5)===0){
        $res .= 'Buzz';
    }
    if($res === '') {
	$res = $i;
    }
    echo $res."\n";
}
?>
view (15 lines, 100 lines of output)
pasted on Jun 2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
for($i=1; $i<=100; $i++) {
    $res= '';
    if(($i%3)===0){
        $res = 'Fizz';		
    }
    if(($i%5)===0){
        $res .= 'Buzz';
    }
    if($res === '') {
	$res = $i;
    }
    echo $res."\n";
}
?>
view (15 lines, 100 lines of output)


Perl:
pasted on Jul 15:
1
for (1 .. 100) { print $_ % 15? $_ % 5 ? $_ % 3 ? $_ . "\n" : "Fizz\n" : "Buzz\n" : "FizzBuzz\n";  }
view (1 line, 100 lines of output)
pasted on Jul 13:
1
for (1 .. 100) { print $_ % 15? $_ % 5 ? $_ % 3 ? $_ . "\n" : "Fizz\n" : "Buzz\n" : "FizzBuzz\n";  }
view (1 line, 100 lines of output)


Python:
pasted on Jul 20:
1
for i in range(1,101):print(i%3<1)*"Fizz"+(i%5<1)*"Buzz"or i
view (1 line, 100 lines of output)
pasted on Jul 17:
1
for i in range(1,101):print(i%3<1)*"Fizz"+(i%5<1)*"Buzz"or i
view (2 lines, 100 lines of output)


Ruby:
pasted on Jul 4:
1
2
3
4
5
6
7
(1..100).each do |num|
    out_str = ""
    out_str << "Fizz" if num % 3 == 0
    out_str << "Buzz" if num % 5 == 0
    out_str = num.to_s if out_str.length ==0
    puts out_str
end
view (7 lines, 100 lines of output)
pasted on Jun 27:
1
2
3
4
5
6
7
8
9
10
11
for i in 1..100
   if i % 15 == 0
      puts "FizzBuzz"
   elsif i % 3 == 0
      puts "Fizz"
   elsif i % 5 == 0
      puts "Buzz"
   else
      puts i
   end
end
view (11 lines, 100 lines of output)