[ create a new paste ] login | about

Recent implementations of FizzBuzz, in:
[ C | Lua ]

C:
pasted on Oct 10:
int main(void) {
    int i;
    int isFizz, isBuzz, isFizzBuzz;

    for(i = 1; i <= 100; i++) {

        /* The following code is NOT tested or recommended... */

        isFizz     = (i % 3 == 0      ) ? 1 : 0;
        isBuzz     = (i % 5 == 0      ) ? 1 : 0;
        isFizzBuzz = (isFizz && isBuzz) ? 1 : 0;
{
        printf(
            (isFizz || isBuzz) ? "%s\n" : "%d\n",
            (
                isFizzBuzz ? "fizzbuzz" :
                isFizz     ? "fizz"     :
                isBuzz     ? "buzz"     :
                i
            )
        );
}
    }

    return 0;
}
view (26 lines, 100 lines of output)
pasted on Oct 10:
int main(void) {
    int i;
    int isFizz, isBuzz, isFizzBuzz;

    for(i = 1; i <= 100; i++) {

        /* The following code is NOT tested or recommended... */

        isFizz     = (i % 3 == 0      ) ? 1 : 0;
        isBuzz     = (i % 5 == 0      ) ? 1 : 0;
        isFizzBuzz = (isFizz && isBuzz) ? 1 : 0;

        printf(
            (isFizz || isBuzz) ? "%s\n" : "%d\n",
            (
                isFizzBuzz ? "fizzbuzz" :
                isFizz     ? "fizz"     :
                isBuzz     ? "buzz"     :
                i
            )
        );
    }

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


Lua:
pasted on Sep 1:
1
2
3
4
5
6
7
8
9
for i = 1, 100 do
    result = (i % 3 == 0 and "Fizz" or "")..(i % 5 == 0 and "Buzz" or "")

    if result == "" then
        result = i
    end

    print(result)
end
view (9 lines, 100 lines of output)
pasted on Sep 1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
for i = 1, 100 do
    result = ""
    if i % 3 == 0 then
        result = result.."Fizz"
    end

    if i % 5 == 0 then
        result = result.."Buzz"
    end

    if result == "" then
        result = i
    end

    print(result)
end
view (16 lines, 100 lines of output)