[ create a new paste ] login | about

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

C:
pasted yesterday:
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==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 (17 lines, 100 lines of output)
pasted on Jun 15:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>

int main() {
  int i;
  for (i=1; i<=100; i++) {
    if (i%3==0) {
      printf("Fizz");
    }
    if (i%5==0) {
      printf("Buzz");
    }
    if (i%3!=0 && i%5!=0) {
      printf("%d", i);
    }
    printf("\n");
  }
  return 0;
}
view (18 lines, 100 lines of output)


C++:
pasted on Jun 9:
#include <stdio.h>

int main(int argc, void** argv) {
    for (int i = 1; i <= 100; i++) {
        bool printed = false;
        if ((i % 3) == 0) {
            std::cout << "Fizz";
            printed = true;
        }
        if ((i % 5) == 0) {
            std::cout << "Buzz";
            printed = true;
        }
        
        if (!printed) {
            std::cout << i;
        }
        
        std::cout << std::endl;
    }

    return 0;
}
view (23 lines, 100 lines of output)
pasted on May 25:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>

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


Haskell:
pasted on Apr 25:
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, 99 comments)
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, 99 comments)


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, 99 comments)
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, 99 comments)


Perl:
pasted on Apr 17:
1
print$_%15?$_%5?$_%3?$_:'Fizz':'Buzz':'FizzBuzz',"\n"for 1..100;
view (1 line, 100 lines of output, 99 comments)


Python:
pasted on Jun 14:
1
2
3
4
5
6
7
8
9
10
11
for  i in range(1,101):
    if not (i % 3 == 0) and not (i % 5 == 0):
        print i
    else:
    	if (i % 3 == 0) and (i % 5 == 0):
        	print "FizzBuzz"
        else:
        	if i % 3 == 0:
    			print "Fizz"
    		if i % 5 == 0:
        		print "Buzz"
view (11 lines, 100 lines of output)
pasted on May 24:
1
print("\n".join("Fizz"*(i%3==0)+"Buzz"*(i%5==0) or str(i) for i in range(1,101)))
view (1 line, 100 lines of output)


Ruby:
pasted on May 31:
1
2
3
4
5
6
(1..100).each{|i|
      x = ''
      x += 'Fizz' if i%3==0
      x += 'Buzz' if i%5==0
      puts(x.empty? ? i : x);
    }
view (6 lines, 100 lines of output)
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, 99 comments)