[ create a new paste ] login | about

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

C:
pasted on Jun 30:
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 Jun 22:
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 Jun 25:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

int main(){

for(int i = 1;i <=100;i++){

    if(!(i%3)){
        cout << "fizz";
    }
    if(!(i%5)){
        cout << "buzz";
    }
    if((i%3)&&(i%5)){
        cout << i;
    }
    cout << endl;
    }
}
view (18 lines, 100 lines of output)
pasted on Jun 20:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using namespace std;

int main()
{
   for (int i = 1; i < 101; ++i)
   {
       if      (i % 3 == 0 && i % 5 == 0) cout << "FizzBuzz";
       else if (i % 3 == 0)               cout << "Fizz";
       else if (i % 5 == 0)               cout << "Buzz";
       else                               cout << i;
       cout << endl;
   }
}
view (14 lines, 100 lines of output)


Haskell:
pasted on May 31:
1
2
3
4
5
6
7
8
9
10
11
y = 5 / 0

z = [1..]

fizzBuzz x 
 | (x `mod` 5 == 0) && (x `mod` 3 == 0) = "FizzBuzz"
 | (x `mod` 5 == 0) = "Buzz"
 | (x `mod` 3 == 0) = "Fizz"
 | otherwise = show x

main = mapM (putStrLn . fizzBuzz) [1..100]
view (13 lines, 100 lines of output)
pasted on May 31:
1
2
3
4
5
6
7
8
9
10
11
12
13
main = mapM putStrLn x

y = 5 / 0

z = [1..]

fizzBuzz x 
 | (x `mod` 5 == 0) && (x `mod` 3 == 0) = "FizzBuzz"
 | (x `mod` 5 == 0) = "Buzz"
 | (x `mod` 3 == 0) = "Fizz"
 | otherwise = show x

x = map fizzBuzz [1..100]
view (13 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 on Jul 1:
<?php

error_reporting(0);

$i = 0;
while($i++ < 100)
{
   if($i % 3 != 0) 
   {
       echo !$$i = $i; // or just $$i = $i; (without the echo), but I kept it as it was in the original code)
   }
   else
   {
       echo 'Fizz';
   }
   if($i % 5 != 0)
   {
       echo $$i; // echo the counter
   }
   else
   {
       echo 'Buzz';
   }
   echo "\n";
}

?>
view (27 lines, 100 lines of output)
pasted on Jun 9:
1
<?for($i=1;$i<=100;$i++){$f=$i%3?'':'fizz';$b=$i%5?'':'buzz';$s=$f.$b?$f.$b:$i;echo $s."\n";}
view (1 line, 100 lines of output)


Perl:
pasted on Jun 9:
1
print 'Fizz'x!($_ % 3) . 'Buzz'x!($_ % 5) || $_, "\n" for 1 .. 100;
view (1 line, 100 lines of output)
pasted on Jun 9:
1
print+(Fizz)[$_%3].(Buzz)[$_%5]||$_,$/for 1..1e2
view (1 line, 100 lines of output)


Python:
pasted on Jun 29:
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 Jun 20:
1
for x in range(1,101):print'Fizz'*(x%3==0)+'Buzz'*(x%5==0)or x
view (1 line, 100 lines of output)


Ruby:
pasted on Jun 29:
1
2
3
4
(1..100).each do |n|
  v = "#{'Fizz' if n % 3 == 0}#{'Buzz' if n% 5 == 0}"
  puts v.empty? ? n : v
end
view (4 lines, 100 lines of output)
pasted on Jun 8:
1
2
3
4
(1..100).each do |n|
  v = "#{'Fizz' if n % 3 == 0}#{'Buzz' if n % 5 == 0}"
  puts v.empty? ? n : v
end
view (4 lines, 100 lines of output)


Scheme:
pasted yesterday:
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)
pasted on Jan 19:
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)