[ create a new paste ] login | about

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

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

int main(void)
{
    int n, notfizz;
    for (n = 1; n < 101; n++) {
        if ((notfizz = n % 3) == 0) 
            printf("fizz");
        if (n % 5 == 0) 
            printf("buzz");
        else if (notfizz) 
            printf("%d", n);
        printf("\n");
    }
    return 0;
}
view (16 lines, 100 lines of output)
pasted yesterday:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>

int main(void)
{
    int n, notfizz;
    for (n = 1; n < 101; n++) {
        if ((notfizz = n % 3) == 0) 
            printf("fizz");
        if (n % 5 == 0) 
            printf("buzz");
        else if (notfizz) 
            printf("%d", n);
        printf("\n");
    }
    return 0;
}
view (16 lines, 100 lines of output)


C++:
pasted 21 hours ago:
1
2
#include <iostream>
int main(int argc, const char * argv[]) { for (int n = 1; n <= 100; ++n) { if (n%3==0 && n%5==0) { std::cout << "fizzbuzz"; } else if (n%3==0) { std::cout << "fizz"; } else if (n%5==0) { std::cout << "buzz"; } else { std::cout << n; }  std::cout << "\n"; } }
view (2 lines, 100 lines of output)
pasted 22 hours ago:
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

int main(int argc, const char * argv[])
{
    for (int n = 1; n <= 100; ++n) { 
        if (n%3==0 && n%5==0) std::cout << "fizzbuzz";
        else if (n%3==0) std::cout << "fizz";
        else if (n%5==0) std::cout << "buzz";
        else std::cout << n;
        std::cout <<"\n"; 
    } 
}
view (12 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 13 hours ago:
1
2
3
<?php
for(;$i++<100;)echo $i%3?$i%5?$i:"":Fizz,$i%5?"":Buzz,"\n" ;
?>
view (3 lines, 100 lines of output)
pasted on Jul 28:
1
2
<?
for(;$i++<100;)echo$i%3?$i%5?$i:"":Fizz,$i%5?"":Buzz,"\n" ;
view (2 lines, 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 7 hours ago:
1
2
3
4
for n in range(1, 101):
    word = "fizz" if not n % 3 else ""
    word += "buzz" if not n % 5 else ""
    print word or n
view (4 lines, 100 lines of output)
pasted yesterday:
1
2
3
4
5
6
7
8
9
for i in range (1,101):
    if i % 3 == 0 and i % 5 == 0:
        print 'fizzbuzz'
    elif i % 3 == 0:
        print 'fizz'
    elif i % 5 == 0:
        print 'buzz'
    else:
        print i
view (9 lines, 100 lines of output)


Ruby:
pasted on Jul 23:
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)