[ create a new paste ] login | about

Recent implementations of FizzBuzz, in:
[ C | C++ | Perl | Python | Scheme ]

C:
pasted on May 8:
#include<stdio.h>
int main(void)
{
    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 (22 lines, 100 lines of output)
pasted on May 2:
#include<stdio.h>
int main(void)
{
    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 (22 lines, 100 lines of output)


C++:
pasted on May 8:
#include<stdio.h>
int main(void)
{
    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 (22 lines, 100 lines of output)
pasted on Apr 5:
#include<stdio.h>
int main(void)
{
    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 (22 lines, 100 lines of output)


Perl:
pasted on May 4:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
for(1..100){
    print "Fizz" if it_is_fizzy ($_);
    print "Buzz" if it_is_buzzy ($_);
    print "$_" if it_is_anything_else ($_);
    print "\n" # if it is anything at all
}

sub it_is_fizzy{
    !($_[0]%3)
}
sub it_is_buzzy{
    !($_[0]%5)
}
sub it_is_anything_else{
    $_[0]%3 and $_[0]%5
}
view (16 lines, 100 lines of output)


Python:
pasted on May 8:
1
2
3
4
5
6
7
8
9
for i in range(1, 101):
    if i % 15 == 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)
pasted on May 8:
1
2
3
4
5
6
7
8
9
for i in range(1, 101):
    if i % 15 == 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)


Scheme:
pasted on May 15:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
(define (iota count . start-step)
  (define (iota-loop count start step)
    (if (zero? count)
        '()
        (cons start
              (iota-loop (- count 1) (+ start step) step))))
  (cond ((null? start-step) (iota-loop count 0 1))
        ((null? (cdr start-step)) (iota-loop count (car start-step) 1))
        (else (iota-loop count (car start-step) (cadr start-step)))))

; ---------------------------------------------------------------------

(define (fizzbuzz n)
  (cond ((= (modulo n 3) (modulo n 5) 0)
         (display "FizzBuzz\n"))
        ((= (modulo n 3) 0) (display "Fizz\n"))
        ((= (modulo n 5) 0) (display "Buzz\n"))
        (else (display n) (display "\n"))))

(for-each fizzbuzz (iota 100 1))
view (20 lines, 100 lines of output)
pasted on Feb 21:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
(define (iota count . start-step)
  (define (iota-loop count start step)
    (if (zero? count)
        '()
        (cons start
              (iota-loop (- count 1) (+ start step) step))))
  (cond ((null? start-step) (iota-loop count 0 1))
        ((null? (cdr start-step)) (iota-loop count (car start-step) 1))
        (else (iota-loop count (car start-step) (cadr start-step)))))

; ---------------------------------------------------------------------

(define (fizzbuzz n)
  (cond ((= (modulo n 3) (modulo n 5) 0)
         (display "FizzBuzz\n"))
        ((= (modulo n 3) 0) (display "Fizz\n"))
        ((= (modulo n 5) 0) (display "Buzz\n"))
        (else (display n) (display "\n"))))

(for-each fizzbuzz (iota 100 1))
view (21 lines, 100 lines of output)