[ create a new paste ] login | about

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

C:
pasted 8 hours ago:
#include <stdio.h>

#define FIZZ "Fizz"
#define BUZZ "Buzz"
int main( int argc, char **argv )
{
	int idx;
        char *out;

	for ( idx = 1; idx <= 100; idx++ )
	{
		if ( idx % 3 == 0 && idx % 5 != 0 )
		{
			out = FIZZ;
		}
		else if ( idx % 3 != 0 && idx % 5 == 0 )
		{
			out = BUZZ;
		}
		else if ( idx % 3 == 0 && idx % 5 == 0 )
		{
			out = FIZZ BUZZ;
		}
		else
		{
			out = NULL;
		}

		if ( out == NULL )
		{
			printf( "%d\n", idx );
		}
		else
		{
			printf( "%s\n", out );
		}
	}
	return 0;
}
view (39 lines, 100 lines of output)
pasted on Dec 15:
#include <stdio.h>

#define FIZZ "Fizz"
#define BUZZ "Buzz"
int main( int argc, char **argv )
{
	int idx;
        char *out;

	for ( idx = 1; idx <= 100; idx++ )
	{
		if ( idx % 3 == 0 && idx % 5 != 0 )
		{
			out = FIZZ;
		}
		else if ( idx % 3 != 0 && idx % 5 == 0 )
		{
			out = BUZZ;
		}
		else if ( idx % 3 == 0 && idx % 5 == 0 )
		{
			out = FIZZ BUZZ;
		}
		else
		{
			out = NULL;
		}

		if ( out == NULL )
		{
			printf( "%d\n", idx );
		}
		else
		{
			printf( "%s\n", out );
		}
	}
	return 0;
}
view (39 lines, 100 lines of output)


C++:
pasted 5 hours ago:
1
2
3
4
5
6
7
8
9
10
11
12
int main () {
    for (int i=1; i<=100; 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;
        
    }

return 0;
}
view (12 lines, 100 lines of output)
pasted 5 hours ago:
1
2
3
4
5
6
7
8
9
10
11
int main () {
    for (int i=1; i<=100; i++) {
        if (i%3 == 0) cout << "Fizz";
        if (i%5 == 0) cout << "Buzz";
        if (i%3 != 0 && i%5 != 0) cout << i;
        cout << endl;
        
    }

return 0;
}
view (11 lines, 100 lines of output)


Haskell:
pasted on Dec 16:
1
main = putStr . unlines $ map (\x -> if mod x 15 == 0 then "FizzBuzz" else if mod x 5 == 0 then "Buzz" else if mod x 3 == 0 then "Fizz" else show x) [1..100]
view (1 line, 100 lines of output)
scarl - pasted on Dec 9:
1
main = putStr . unlines $ map (\x -> if mod x 15 == 0 then "FizzBuzz" else if mod x 5 == 0 then "Buzz" else if mod x 3 == 0 then "Fizz" else show x) [1..100]
view (1 line, 100 lines of output)


Lua:
pasted on Nov 8:
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 Aug 19:
print([[
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz
]])
view (102 lines, 101 lines of output)


OCaml:
pasted on Oct 24:
1
2
3
4
5
6
7
8
9
10
11
let fizzbuzz index =
  match index mod 3, index mod 5 with
    0, 0 -> "FizzBuzz"
  | 0, _ -> "Fizz"
  | _, 0 -> "Buzz"
  | _    -> string_of_int index
 
let _ =
  for index = 1 to 100 do 
    print_endline (fizzbuzz index) 
  done
view (11 lines, 100 lines of output)
pasted on Oct 24:
1
2
3
4
5
6
7
8
9
let fizzbuzz index =
  match index mod 3, index mod 5 with
    0, 0 -> "FizzBuzz"
  | 0, _ -> "Fizz"
  | _, 0 -> "Buzz"
  | _    -> string_of_int index
 
let _ =
  for index = 1 to 100 do print_endline (fizzbuzz index) done
view (9 lines, 100 lines of output)


PHP:
pasted yesterday:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
function fizzBuzz($n) {
  if ($n%15==0) {
      echo "FizzBuzz";
  } elseif ($n%3==0) {
      echo "Fizz";
  } elseif ($n%5==0) {
      echo "Buzz";
  } else {
      echo $n;
  }
}

for ($i=1; $i<=100; $i++) {
  fizzBuzz($i);
  echo "\n";
}
?>
view (18 lines, 100 lines of output)
pasted on Dec 11:
1
2
3
4
5
6
7
8
9
10
11
12
13
<?
for ($i=1; $i<=100; $i++) {
    if ($i%3==0 && $i%5==0) {
        echo 'FizzBuzz';
    }else if($i%3==0){
        echo 'Fizz';
    }else if($i%5==0){
        echo 'Buzz';
    }else{
        echo $i;
    }
    echo "\n";
}
view (13 lines, 100 lines of output)


Perl:
pasted on Dec 13:
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/perl
for ($i = 1; $i < 101; $i++) {
    if ($i % 15 < 1) {
        print "FizzBuzz\n";
    } elsif ($i % 3 < 1) {
        print "Fizz\n";
    } elsif ($i % 5 < 1) {
        print "Buzz\n";
    } else {
        print "$i\n";
    }
}
view (12 lines, 100 lines of output)
pasted on Oct 15:
1
2
3
4
5
6
7
8
9
10
11
12
13
my $x = false, $y = false; 

for (my $i=1; $i<=100; $i++) {
    if ($i % 15 == 0) { 
        print "FizzBuzz\n" ;
    } elsif ($i % 3 == 0) { 
        print "Fizz\n";
    } elsif ($i % 5 == 0) { 
        print "Buzz\n";
    } else { 
        print "$i\n"; 
    }
}
view (13 lines, 100 lines of output)


Python:
pasted on Nov 28:
1
2
3
4
5
for y in range(1,101):    
  if(y % 3 == 0 and y % 5 == 0): print "fizzbuzz"
  elif(y % 5 == 0): print "buzz"
  elif(y % 3 == 0): print "fizz"
  else: print y
view (5 lines, 100 lines of output)
pasted on Nov 28:
1
2
3
4
5
for y in range(1,101):    
  if(y % 3 == 0 and y % 5 == 0): print "fizzbuzz"
  elif(y % 5 == 0): print "buzz"
  elif(y % 3 == 0): print "fizz"
  else: print y
view (5 lines, 100 lines of output)


Ruby:
pasted on Dec 16:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
for i in 1..100

    output = ""

    if i % 3 == 0
        output += "Fizz"
    end
    if i % 5 == 0
        output += "Buzz"
    end

    puts(output.empty? ? i : output);

end
view (14 lines, 100 lines of output)
pasted on Dec 16:
1
2
3
4
5
6
7
8
9
10
11
12
for i in 1..100
    if (i%3 == 0) && (i%5 ==0)
        print "FIZZBUZZ"
    elsif (i%3 ==0)
        print "FIZZ"
    elsif (i % 5 ==0)
        print "BUZZ"
    else
        print i
    end
        print "\n"
end
view (12 lines, 100 lines of output)