[ create a new paste ] login | about

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

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

int main(void)
{
    int i;
    for (i = 1; i <= 100; i++) {
        if (i % 3 == 0 && i % 5 == 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 (18 lines, 100 lines of output)
pasted on Jul 28:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>

int main(void)
{
    int i;
    for (i = 1; i <= 100; i++) {
        if (i % 3 == 0 && i % 5 == 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 (18 lines, 100 lines of output)


C++:
pasted on Jul 27:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

int main() {
  int remainder;
  for(int i=0; i<100; i++) {
    remainder = (i+1)%15;
    if(remainder == 0) {std::cout << "FizzBuzz";}
    else if(remainder%3 == 0) {std::cout << "Fizz";}
    else if(remainder%5 == 0) {std::cout << "Buzz";}
    else {std::cout << i + 1;}
    std::cout << std::endl;
  }
  return 0;
}
view (14 lines, 100 lines of output)
pasted on Jul 27:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>

int main() {
  int remainder;
  int i;
  for(i=0; i<100; i++) {
    remainder = (i+1)%15;
    if(remainder == 0) {printf("FizzBuzz");}
    else if(remainder%3 == 0) {printf("Fizz");}
    else if(remainder%5 == 0) {printf("Buzz");}
    else {printf("%d", i+1);}
    printf("\n");
  }
  return 0;
}
view (15 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)
pasted on Mar 2:
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 10 hours ago:
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 yesterday:
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 10 hours ago:
1
2
3
for(1..100){++$x%3or
print"Fizz",$_='';++$y%5or
print"Buzz",$_='';print"$_\n"}
view (3 lines, 100 lines of output)
pasted 10 hours ago:
1
for(1..100){++$x%3or print"Fizz",$_='';++$y%5or print"Buzz",$_='';print"$_\n"}
view (1 line, 100 lines of output)


Python:
pasted on Jul 25:
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)
pasted on Jul 23:
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 9 hours ago:
1
2
3
4
5
6
7
1.upto 100 do |n|
    res = ''
    res << 'Fizz' if n  % 3 == 0
    res << 'Buzz' if n  % 5 == 0
    res << n.to_s if res == ''
    puts res
end
view (7 lines, 100 lines of output)
pasted 9 hours ago:
1
2
3
4
5
6
7
1.upto 100 do |n|
    res = ''
    res << 'Fizz' if n  % 3 == 0
    res << 'Buzz' if n  % 5 == 0
    res << n.to_s if res == ''
    puts res
end
view (7 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)