[ create a new paste ] login | about

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

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

int main()
{
    int theFizzAndTheBuzzAndTheFizzBuzz;
    for (theFizzAndTheBuzzAndTheFizzBuzz = 1; theFizzAndTheBuzzAndTheFizzBuzz <= 100; ++theFizzAndTheBuzzAndTheFizzBuzz)
    {
        if (theFizzAndTheBuzzAndTheFizzBuzz % 3 == 0 && theFizzAndTheBuzzAndTheFizzBuzz % 5 == 0)
            printf("FizzBuzz\n");
        else if (theFizzAndTheBuzzAndTheFizzBuzz % 3 == 0)
            printf("Fizz\n");
        else if (theFizzAndTheBuzzAndTheFizzBuzz % 5 == 0)
            printf("Buzz\n");
        else
            printf("%d\n", theFizzAndTheBuzzAndTheFizzBuzz);
    }
    return 0;
}
view (18 lines, 100 lines of output)
aaku143 - pasted on Sep 17:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>

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


C++:
pasted on Sep 8:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main() {
    bool three;
    bool five;
    for (int i = 1; i <= 100; ++i) {
        three = i % 3 == 0;
        five = i % 5 == 0;
        if (three) {
            std::cout << "Fizz";
        }
        if (five) {
            std::cout << "Buzz";
        } else if (!three) {
            std::cout << i;
        }

        std::cout << endl;
    }
}
view (18 lines, 100 lines of output)
pasted on Sep 8:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int main() {
    bool three;
    bool five;
    for (int i = 1; i <= 100; ++i) {
        three = i % 3 == 0;
        five = i % 5 == 0;
        if (three) {
            std::cout << "Fizz";
        }
        if (five) {
            std::cout << "Buzz";
        }
        if (!three && !five) {
            std::cout << i;
        }

        std::cout << endl;
    }
}
view (19 lines, 100 lines of output)


Haskell:
pasted on Sep 9:
1
2
3
4
5
6
7
8
main = putStr . unlines $ map fizzBuzzer [1..100]

fizzBuzzer  :: Integer -> String
fizzBuzzer x
  | mod x 15 == 0    = "FizzBuzz"
  | mod x 5  == 0     = "Buzz"
  | mod x 3  == 0     = "Fizz"
  | otherwise            = show x
view (8 lines, 100 lines of output)
pasted on Aug 27:
1
2
3
4
5
6
7
8
fizzbuzz :: Integer -> String
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 = sequence $ (putStrLn .) fizzbuzz `map` [1 .. 100]
view (8 lines, 100 lines of output)


Lua:
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)
pasted on Aug 19:
1
for i=1,100 do print(i%15<1 and"FizzBuzz"or i%3<1 and"Fizz"or i%5<1 and"Buzz"or i)end
view (1 line, 100 lines of output)


PHP:
pasted on Sep 12:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php

define('START', 1);
define('STOP', 100);

for($i = START; $i <= STOP; ++$i) {
	$output = '';
	if($i % 3 == 0) {
		$output .= 'Fizz';	
	}
	if($i % 5 == 0) {
		$output .= 'Buzz';
	}
	if(empty($output)) {
		$output = $i;
	}
	echo $output . "\n";
}
view (18 lines, 100 lines of output)
KyleMassacre - pasted on Sep 4:
1
2
3
4
5
6
7
<?php
for($i = 1; $i <= 100; $i++)
{
    echo ($i%3==0?($i%5==0?"FizzBuzz":"Fizz")
    :($i%5==0?"Buzz": $i))."\n";
}
?>
view (7 lines, 100 lines of output)


Perl:
pasted on Aug 27:
1
2
3
4
5
6
7
8
9
10
11
12
print sub {
	my @out;
	for (1..100) {
		push @out, do {
			if ($_ % 3 == 0 and $_ % 5 == 0) { "fizzbuzz"
			} elsif ($_ % 3 == 0) { "fizz"
			} elsif ($_ % 5 == 0) {	"buzz"
			} else { $_ }
		};
	}
	return join "\n", @out;
}->();
view (12 lines, 100 lines of output)
pasted on Aug 27:
1
2
3
4
5
6
7
8
9
10
11
12
print sub {
	my @out;
	for (1..100) {
		push @out, do {
			if ($_ % 3 == 0 and $_ % 5 == 0) { "fizzbuzz"
			} elsif ($_ % 3 == 0) { "fizz"
			} elsif ($_ % 5 == 0) {	"buzz"
			} else { $_ }
		};
	}
	return join "\n", @out;
}->();
view (12 lines, 100 lines of output)


Python:
pasted on Sep 18:
1
2
3
4
5
6
7
8
9
for x in range(1,101):
  if x%3 == 0 and x%5 == 0:
    print "FizzBuzz"
  elif x%3 == 0:
    print "Fizz"
  elif x%5 == 0:
    print "Buzz"
  else:
    print x
view (9 lines, 100 lines of output)
pasted on Sep 18:
1
2
3
4
5
6
7
8
9
10
11
#!/usr/local/bin/python2.7
    
for x in range(1,101):
  if x%3 == 0 and x%5 == 0:
    print "FizzBuzz"
  elif x%3 == 0:
    print "Fizz"
  elif x%5 == 0:
    print "Buzz"
  else:
    print x
view (11 lines, 100 lines of output)


Ruby:
pasted 1 minute ago:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
for n in 1..100 do
    i_3= n%3==0
    i_5= n%5==0
    case
        when i_3&&i_5
            puts 'fizzbuzz'
        when i_3
            puts 'fizz'
        when i_5
            puts 'buzz'
        else
            puts n
    end
end
view (14 lines, 100 lines of output)
pasted 2 minutes ago:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
for n in 1..100 do
    i_3=(n%3==0)
    i_5=(n%5==0)
    case
        when i_3&&i_5
            puts 'fizzbuzz'
        when i_3
            puts 'fizz'
        when i_5
            puts 'buzz'
        else
            puts n
    end
end
view (14 lines, 100 lines of output)


Scheme:
pasted on May 30:
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)