[ create a new paste ] login | about

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

C:
pasted on Dec 9:
#include<stdio.h>
#include<math.h>

int main()
{
	int i;
	for(i=1;i<101;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 (36 lines, 100 lines of output)
pasted on Dec 9:
#include<stdio.h>
#include<math.h>

int main()
{
	int i;
	for(i=1;i<101;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 (36 lines, 100 lines of output)


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

int main()
{
	int i;
	for(i=1;i<101;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 (36 lines, 100 lines of output)
pasted on Dec 4:
#include<stdio.h>
#include<math.h>

int main()
{
	int i;
	for(i=1;i<101;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 (36 lines, 100 lines of output)


Haskell:
pasted on Nov 5:
1
2
3
4
5
6
7
8
9
10
newtype FizzBuzz = MakeFizzBuzz Int

instance Show FizzBuzz where
  show (MakeFizzBuzz x)
    | (x `mod` 3 == 0) && (x `mod` 5 == 0)  =  "fizzbuzz"
    | (x `mod` 3 == 0)                      =  "fizz"
    | (x `mod` 5 == 0)                      =  "buzz"
    | otherwise                             =  show x

main = mapM_ print [MakeFizzBuzz x | x <- [1..100]]
view (10 lines, 100 lines of output)
pasted on Sep 4:
1
2
3
4
5
6
7
8
9
10
newtype FizzBuzz = MakeFizzBuzz Int

instance Show FizzBuzz where
  show (MakeFizzBuzz x)
    | (x `mod` 3 == 0) && (x `mod` 5 == 0)  =  "fizzbuzz"
    | (x `mod` 3 == 0)                      =  "fizz"
    | (x `mod` 5 == 0)                      =  "buzz"
    | otherwise                             =  show x

main = mapM_ print [MakeFizzBuzz x | x <- [1..100]]
view (10 lines, 100 lines of output)


Lua:
pasted on Dec 7:
1
2
3
4
5
6
7
for i=1, 100 do
    output = ''
    if i%3 == 0 then output = output..'Fizz' end
    if i%5 == 0 then output = output..'Buzz' end
    if output == '' then output = i end
    print(output)
end
view (7 lines, 100 lines of output)
pasted on Oct 18:
1
2
3
4
5
6
7
8
for i=1, 100 do
    fizz = (i % 3 == 0)
    buzz = (i % 5 == 0)
    if fizz and buzz then print("FIZZBUZZ")
    elseif fizz then print("FIZZ")
    elseif buzz then print("BUZZ")
    else print(i) end
end
view (8 lines, 100 lines of output)


PHP:
pasted on Dec 6:
1
2
3
4
5
6
7
8
9
<?php
for($i=1;$i<=100;$i++){
$str = '';
if($i%3==0) { $str .= 'Fizz'; }
if($i%5==0) { $str .= 'Buzz'; }
if($str=='') { echo $i; } else { echo $str; }
echo "\n";
}
?>
view (9 lines, 100 lines of output)
pasted on Oct 14:
1
2
3
4
5
6
7
8
9
<?php
for($i=1;$i<=100;$i++){
$str = '';
if($i%3==0) { $str .= 'Fizz'; }
if($i%5==0) { $str .= 'Buzz'; }
if($str=='') { echo $i; } else { echo $str; }
echo "\n";
}
?>
view (9 lines, 100 lines of output)


Perl:
pasted on Aug 1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
for (1..100){
    my $f = $_ % 3;
    my $b = $_ % 5;
    if( !$f ){
        print "fizz";
    }
    if( !$b ){
        print "buzz"
    }
    if( $f && $b ){
        print $_;
    }
    print "\n";
}
view (14 lines, 100 lines of output)


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


Ruby:
pasted on Aug 15:
1
2
3
4
5
6
1.upto(100) do |i|
  out = nil
  out = out.to_s + 'Fizz' if i % 3 == 0
  out = out.to_s + 'Buzz' if i % 5 == 0
  puts out || i
end
view (6 lines, 100 lines of output)
pasted on Aug 15:
1
2
3
4
5
6
1.upto(100) do |i|
  out = nil
  out = out.to_s + 'Fizz' if i % 3 == 0
  out = out.to_s + 'Buzz' if i % 5 == 0
  puts out || i
end
view (6 lines, 100 lines of output)


Scheme:
pasted on Jun 26:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
(define (fizz-buzzify index)
  (letrec ((fizz-val (lambda (i s) ;Hey, I found a use for letrec.
                       (if (> i 0)
                           (fizz-val (- i 1)
                                     (string-append
                                      (cond
                                        ((= (modulo i 15) 0) "FizzBuzz")
                                        ((= (modulo i 5) 0) "Buzz")
                                        ((= (modulo i 3) 0) "Fizz")
                                        (else (number->string i))) "\n" s))
                           s))))
    (fizz-val index "")))

(display (fizz-buzzify 100))
view (14 lines, 100 lines of output)