[ create a new paste ] login | about

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

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

int main(int argc, char *argv[]) {
    int i;

    for(i = 1; i <= 100; i++) {
        if(i % (3*5) == 0) printf("FizzBuzz\n");
        else if(i % 5 == 0) printf("Buzz\n");
        else if(i % 3 == 0) printf("Fizz\n");

        /* default */
        else printf("%d\n", i);
    }

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

int main(int argc, char *argv[]) {
    int i;

    for(i = 1; i <= 100; i++) {
        if(i % (3*5) == 0) printf("FizzBuzz\n");
        else if(i % 5 == 0) printf("Buzz\n");
        else if(i % 3 == 0) printf("Fizz\n");

        /* default */
        else printf("%d\n", i);
    }

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


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

int main(int argc, char *argv[]) {
    int i;

    for(i = 1; i <= 100; i++) {
        if(i % (3*5) == 0) printf("FizzBuzz\n");
        else if(i % 5 == 0) printf("Buzz\n");
        else if(i % 3 == 0) printf("Fizz\n");

        /* default */
        else printf("%d\n", i);
    }

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

int main() {
  int i=0;
  for (i=1; i<101; i++){
    int db = 0;
    db = db ^ 1 * (!(i%3)) ^ 2*(!(i%5));
    if (db&1){printf("fizz");} //db=01 or 11
    if (db&2){printf("buzz");} //db=10 or 11
    if (!db){printf("%d",i);}  //db=00
    printf("\n");
  }
}
    
view (15 lines, 100 lines of output)


D:
pasted on Nov 16:
1
2
3
4
5
6
7
8
9
10
import std.stdio;

void main() {
    for (int i = 1; i <= 100; i++) {
        if (i % 3 == 0) writef("Fizz");
        if (i % 5 == 0) writef("Buzz");
        else if(i % 3 != 0) writef("%d", i);
        writef("\n");
    }
}
view (10 lines, 100 lines of output)
pasted on Nov 16:
1
2
3
4
5
6
7
8
9
10
import std.stdio;

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


Haskell:
pasted on Apr 7:
1
2
3
4
5
6
7
fb i
 | i `mod` 3 == 0 && i `mod` 5 == 0 = "FizzBuzz"
 | i `mod` 3 == 0 = "Fizz"
 | i `mod` 5 == 0 = "Buzz"
 | otherwise      = show i

main = mapM_ (putStrLn . fb) [1..100] 
view (7 lines, 100 lines of output)
pasted on Apr 7:
1
2
3
4
5
6
7
fb i
 | i `mod` 3 == 0 && i `mod` 5 == 0 = "FizzBuzz"
 | i `mod` 3 == 0 = "Fizz"
 | i `mod` 5 == 0 = "Buzz"
 | otherwise      = show i

main = mapM_ (putStrLn . fb) [1..100] 
view (7 lines, 100 lines of output)


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


PHP:
pasted on Apr 15:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
for ( $i = 1; $i <= 100; $i++ ) {
    if ( $i % 15 == 0 ) {
        print 'FizzBuzz';
    } else if ( $i % 3 == 0 ) {
        print 'Fizz';
    } else if ( $i % 5 == 0 ) {
        print 'Buzz';
    } else {
        print $i;
    }
    print "\n";
}
// <プークスクス
?>
view (15 lines, 100 lines of output)
pasted on Apr 15:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
for($i=1; $i<=100; $i++){

    if($i%15 === 0){
      echo 'FizzBuzz';
    } elseif ($i%3 === 0){
      echo 'Fizz';
    } elseif ($i%5 === 0){
      echo 'Buzz';
    } else {
      echo $i;
    }
    echo "\n";
}
view (14 lines, 100 lines of output)


Perl:
pasted 6 hours ago:
1
2
3
4
5
6
for (1..100) {
	print "Fizz" if (not $_%3);
	print "Buzz" if (not $_%5);
	print if ($_%5 && $_%3);
	print "\n";
}
view (6 lines, 100 lines of output)
pasted on Mar 26:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
foreach my $i (1..100)
{
    my $result = "";

    if ($i%3 == 0)
    {    
        $result = "Fizz";
    }
    if ($i%5 == 0)
    {
        $result .= "Buzz";
    }
    if (length($result) == 0) { $result = $i;}
    print "$result\n";
    
}
view (16 lines, 100 lines of output)


Python:
pasted 5 hours ago:
1
for i in ["fizz" if i%3==0 and i%5!=0 else "buzz" if i%5==0 and i%3!=0 else "fizzbuzz" if i%3==0 and i%5==0 else str(i) for i in xrange(1,101)]: print i
view (1 line, 100 lines of output)
pasted on Apr 11:
1
2
3
4
5
6
7
8
9
10
11
12
13
def fizzbuzz(x):
      result = ""
      if (x % 3 == 0):
            result = result + "Fizz"
      if (x % 5 == 0):
            result = result + "Buzz"
      if result == "":
            return x
      else:
            return result

for i in range(1,101):
      print (fizzbuzz(i))
view (13 lines, 100 lines of output)


Ruby:
pasted on Mar 28:
1
puts (0..99).map {|i| srand(46308667) if (i%15).zero?; ["FizzBuzz", "Buzz", i+1, "Fizz"][rand(4)]}
view (1 line, 100 lines of output)
pasted on Mar 25:
1
puts (0..99).map {|i| srand(46308667) if (i%15).zero?; ["FizzBuzz", "Buzz", i+1, "Fizz"][rand(4)]}
view (1 line, 100 lines of output)