[ create a new paste ] login | about

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

C:
pasted 6 hours ago:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h>

int main(void)
{
int i;
for(i = 1; i <= 100; i++) 
{
    if (!(i % 3)) {
        if (!(i % 5)) printf("%s\n", "FizzBuzz");
        else printf("%s\n", "Fizz");
    }

    else if (!(i % 5)) printf("%s\n", "Buzz");
    else printf("%d\n", i);
}
return 0;
}
view (17 lines, 100 lines of output)
pasted on Aug 27:
#include <stdio.h>
int main()
{
int i;
for(i=1;i<=100;i++)
 {
   if(i%5==0 && i%3==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 (26 lines, 100 lines of output)


C++:
pasted on Aug 27:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int main ()
{
       for (int i = 1; i <= 100; i++) 
       {
               if ((i % 15) == 0)
                       cout << "FizzBuzz\n";
               else if ((i % 3) == 0)
                       cout << "Fizz\n";
               else if ((i % 5) == 0)
                       cout << "Buzz\n";
               else
                       cout << i << "\n";
       }
return 0;
       
}
view (16 lines, 100 lines of output)
pasted on Aug 24:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int main ()
{
       for (int i = 1; i <= 100; i++) 
       {
               if ((i % 15) == 0)
                       cout << "FizzBuzz\n";
               else if ((i % 3) == 0)
                       cout << "Fizz\n";
               else if ((i % 5) == 0)
                       cout << "Buzz\n";
               else
                       cout << i << "\n";
       }
return 0;
       
}
view (16 lines, 100 lines of output)


Haskell:
pasted on Jul 20:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import Control.Monad
main :: IO ()
aaaaa :: (Int,String) -> String
aaaaa (a,b) = b
uuuuu :: (Int,String) -> Int
uuuuu (a,b) = a
main = do
    forM_ [1..100] $ \x -> do
        potato x [(3,"Fizz"),(5,"Buzz")] where
            potato :: Int -> [(Int,String)] -> IO ()
            potato x it@(i:is)
                | x `mod` (uuuuu i) == 0 = carrot x it
                | otherwise = potato x is
            potato x _ = print x
            carrot :: Int -> [(Int,String)] -> IO ()
            carrot x (i:is)
                | x `mod` (uuuuu i) == 0 = do
                    putStr $ aaaaa i
                    carrot x is
                | otherwise = carrot x is
            carrot x _ = putStr "\n"
view (21 lines, 100 lines of output)
pasted on Jul 20:
1
2
3
4
5
6
7
8
import Control.Monad
main :: IO ()
main = do
    forM_ [1..100] $ \x -> do
        if x `mod` 3==0 then putStr "Fizz" else return ()
        if x `mod` 5==0 then putStr "Buzz" else return ()
        if not (x `mod` 3==0 || x `mod` 5==0) then putStr . show $ x else return ()
        putStrLn ""
view (8 lines, 100 lines of output)


Lua:
pasted on Mar 19:
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 31:
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
for($i=1;$i<=100;$i++){
    if($i%15 == 0)
        echo "FizzBuzz";
    else if ($i%5==0)
        echo "Buzz";
    else if($i%3 ==0)
        echo "Fizz";
    else
        echo $i;
    echo "\n";
}
?>
view (13 lines, 100 lines of output)
pasted on Jul 30:
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
for($i=1;$i<=100;$i++){
    if($i%15 == 0)
        echo "FizzBuzz";
    else if ($i%5==0)
        echo "Buzz";
    else if($i%3 ==0)
        echo "Fizz";
    else
        echo $i;
    echo "\n";
}
?>
view (13 lines, 100 lines of output)


Perl:
pasted on Aug 27:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
for $i (1..100)
{
   $message="";
   if($i%3==0)
   {
       $message.="Fizz";
   }
   if($i%5==0)
   {
       $message.="Buzz";
   }
   if($message eq "")
   {
       $message=$i;
   }
   print $message."\n";
}
view (17 lines, 100 lines of output)
pasted on Aug 4:
1
2
3
for(1..100){++$x%3or
print"Fizz",$_='';++$y%5or
print"Buzz",$_='';print"$_\n"}
view (3 lines, 100 lines of output)


Python:
pasted on Aug 5:
1
2
3
4
5
6
7
8
9
for x in range(1,101):
		s = ""
		if x % 3 == 0:
			s += "Fizz"
		if x % 5 == 0:
			s += "Buzz"
		if s == "":
			s = x
		print s
view (9 lines, 100 lines of output)
pasted on Aug 3:
1
2
3
4
5
6
7
8
9
for i in range(1,101):
    if i % 3 == 0 and i % 5 == 0:
        print("FizzBuzz");
    elif i % 3 == 0:
        print("Fizz")
    elif i % 5 == 0:
        print("Buzz")
    else:
        print(i);
view (9 lines, 100 lines of output)


Ruby:
pasted on Aug 16:
1
2
3
4
5
6
7
8
9
10
11
1.upto(100) 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)
pasted on Aug 16:
1
2
3
4
5
6
7
8
9
10
11
    1.upto(100) 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 (12 lines, 100 lines of output)


Scheme:
pasted on Jul 4:
1
2
3
4
5
6
7
8
(do ((i 1 (+ i 1)))
    ((> i 100))
    (display
      (cond ((= 0 (modulo i 15)) "FizzBuzz")
            ((= 0 (modulo i 3))  "Fizz")
            ((= 0 (modulo i 5))  "Buzz")
            (else                i)))
    (newline))
view (8 lines, 100 lines of output)