[ create a new paste ] login | about

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

C:
pasted on Jul 20:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int main() {


    int i = 1;
    while( i < 101 ) {

        if( i % 15 == 0 ) {
            printf("FizzBuzz\n");
        } else if ( i % 5 == 0 ) {
            printf("Buzz\n");
        } else if ( i % 3 == 0 ) {
            printf("Fizz\n");
        } else {
            printf("%d\n",i);
        }
        i++;
    }

    return 0;
}
view (20 lines, 100 lines of output)
pasted on Jul 18:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int main() {


    int i = 1;
    while( i < 101 ) {

        if( i % 15 == 0 ) {
            printf("FizzBuzz\n");
        } else if ( i % 5 == 0 ) {
            printf("Buzz\n");
        } else if ( i % 3 == 0 ) {
            printf("Fizz\n");
        } else {
            printf("%d\n",i);
        }
        i++;
    }

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


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

int main(int argc, char **args)
{
	for (int i = 1; i <= 100; ++i)
	{
		bool div3 = (i % 3) == 0;
		bool div5 = (i % 5) == 0;
		if (div3 && div5) printf("FizzBuzz\n");
		else if (div3) printf("Fizz\n");
		else if (div5) printf("Buzz\n");
		else printf("%d\n", i);
	}
	
	return 0;
}
view (16 lines, 100 lines of output)
pasted on Jul 21:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;

int main()
{
    for (int index = 1; index <= 100; ++index)
    {
        if (index % 3 != 0 && index % 5 != 0)
            cout << index;
        if (index % 3 == 0)
            cout << "Fizz";
        if (index % 5 == 0)
            cout << "Buzz";
        cout << endl;
    }
    return 0;
}
view (18 lines, 100 lines of output)


Haskell:
pasted on Jun 16:
1
2
3
4
5
main = mapM_ putStrLn fb

--fb = [max(show x)$[n|(f,n)<-[(3,"Fizz"),(5,"Buzz")],mod x f<1]>>=id|x<-[1..100]]
-- Old:
fb = [max(show x)(concat[n|(f,n)<-[(3,"Fizz"),(5,"Buzz")],mod x f==0])|x<-[1..100]]
view (5 lines, 100 lines of output)
pasted on Jun 16:
1
2
3
4
5
main = mapM_ putStrLn fb

fb = [max(show x)$[n|(f,n)<-[(3,"Fizz"),(5,"Buzz")],mod x f<1]>>=id|x<-[1..100]]
-- Old:
--   [max(show x)(concat[n|(f,n)<-[(3,"Fizz"),(5,"Buzz")],mod x f==0])|x<-[1..100]]
view (5 lines, 100 lines of output)


Lua:
pasted on Jun 17:
1
2
3
4
5
6
7
8
9
10
local loop = 1

while loop < 101 do
    if (loop%3 == 0) and (loop%5 == 0) then print("FizzBuzz")
        elseif (loop % 3) == 0 then print("Fizz")
        elseif (loop % 5) == 0 then print("Buzz")
        else print(loop) 
    end
    loop = loop + 1
end
view (10 lines, 100 lines of output)
Willox - pasted on May 25:
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 Jul 22:
1
<?for(;$i++<100;)echo$i%3?$i%5?$i:"":Fizz,$i%5?"":Buzz,"\n" ;
view (1 line, 100 lines of output)
pasted on Jul 19:
1
<?for(;$i++<100;)echo$i%3?$i%5?$i:"":Fizz,$i%5?"":Buzz,"\n" ;
view (1 line, 100 lines of output)


Perl:
pasted on May 29:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
for ($i=1; $i <= 100; $i++) {
    if (($i%3 == 0) and ($i%5 == 0)){
        print ("FizzBuzz\n");
    }
    elsif ($i%3 == 0){
        print ("Fizz\n");
    }
    elsif ($i%5 == 0){
        print ("Buzz\n");
    }
    else{
        print ("$i\n");
    }
}
view (14 lines, 100 lines of output)
pasted on May 22:
1
print 'Fizz'x!($_ % 3) . 'Buzz'x!($_ % 5) || $_, "\n" for 1 .. 100;
view (1 line, 100 lines of output)


Python:
pasted on Jul 22:
1
for i in xrange(1,101): print (i%3==0)*"Fizz" + (i%5==0)*"Buzz" or i
view (1 line, 100 lines of output)
pasted on Jul 20:
1
2
3
4
5
6
7
8
def fizzbuzz(n):
  for i in range(1, n+1):
    if i % 15 == 0: print 'FizzBuzz'
    elif i % 5 == 0: print 'Buzz'
    elif i % 3 == 0: print 'Fizz'
    else: print i

fizzbuzz(100)
view (8 lines, 100 lines of output)


Ruby:
pasted yesterday:
1
2
3
4
5
6
7
8
9
10
11
(1..100).each {|x|
    if (x % 3 == 0 and x % 5 == 0)
        puts "FizzBuzz"
    elsif (x % 3 == 0)
        puts "Fizz"
    elsif (x % 5 == 0)
        puts "Buzz"
    else
        puts x
    end
}
view (11 lines, 100 lines of output)
pasted on Jun 18:
1
2
3
4
5
6
1.upto(100) do |n|
  print "Fizz" if a = (n % 3).zero?
  print "Buzz" if b = (n % 5).zero?
  print n unless (a || b)
  print "\n"
end
view (6 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)