Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

FizzBuzz everyday

Name: Anonymous 2011-09-14 3:47

(use '[match.core :only (match)])

(doseq [n (range 1 101)]
  (println (match [(mod n 3) (mod n 5)]
                  [0 0] "FizzBuzz"
                  [0 _] "Fizz"
                  [_ 0] "Buzz"
                  :else n)))

Name: Anonymous 2011-09-14 4:26

#include <stdio.h>
int main() {
    int i;
    for (i = 1; i < 101; i++)
        if (!(i % 15))
            puts("FizzBuzz");
        else if (!(i % 3))
            puts("Fizz");
        else if (!(i % 5))
            puts("Buzz");
        else
            printf("%d\n", i);
    return 0;
}


Compile with gcc -Wall -Werror -Wextra -ansi -pedantic -O2 -g -o fizzbuzz fizzbuzz.c

Name: Anonymous 2011-09-14 4:31

;; nasm linux x86
section .text
    global _start

_start:
    mov eax, 4
    xor ebx, ebx
    xor ecx, ecx
    xor edx, edx

startloop:
    inc ecx
    cmp ecx, 101
    je endloop

    add bx, 0x0101

    cmp bl, 3
    je buzz

    cmp bh, 5
    je fizz

    cmp bx, 0x0503
    je fizzbuzz

    ;; print number
    pusha

    xor ebx, ebx
    mov ecx, edx
    add ecx, snums
    mov edx, 5
    int 0x80

    popa

    add edx, 5

    jmp startloop
buzz:
    ;; print buzz
    pusha

    xor ebx, ebx
    mov ecx, sbuzz
    mov edx, sbuzzsize
    int 0x80

    popa

    xor bl, bl
    add edx, 5
    jmp startloop
fizz:
    ;; print fizz
    pusha

    xor ebx, ebx
    mov ecx, sfizz
    mov edx, sfizzsize
    int 0x80

    popa

    xor bh, bh
    add edx, 5
    jmp startloop
fizzbuzz:
    ;; print fizzbuzz
    pusha

    xor ebx, ebx
    mov ecx, sfizzbuzz
    mov edx, sfizzbuzzsize
    int 0x80

    popa

    xor bx, bx
    add edx, 5
    jmp startloop

endloop:   
    ;; end
    mov eax, 1
    mov ebx, 0
    int 0x80

section .data
    sfizz db 'fizz',0x0d,0x0a
    sfizzsize equ $-sfizz
    sbuzz db 'buzz',0x0d,0x0a
    sbuzzsize equ $-sbuzz
    sfizzbuzz db 'fizzbuzz',0x0d,0x0a
    sfizzbuzzsize equ $-sfizzbuzz
    snums db '  1',0x0d,0x0a,'  2',0x0d,0x0a,'  3',0x0d,0x0a,'  4',0x0d,0x0a,'  5',0x0d,0x0a,'  6',0x0d,0x0a,'  7',0x0d,0x0a,'  8',0x0d,0x0a,'  9',0x0d,0x0a,' 10',0x0d,0x0a,' 11',0x0d,0x0a,' 12',0x0d,0x0a,' 13',0x0d,0x0a,' 14',0x0d,0x0a,' 15',0x0d,0x0a,' 16',0x0d,0x0a,' 17',0x0d,0x0a,' 18',0x0d,0x0a,' 19',0x0d,0x0a,' 20',0x0d,0x0a,' 21',0x0d,0x0a,' 22',0x0d,0x0a,' 23',0x0d,0x0a,' 24',0x0d,0x0a,' 25',0x0d,0x0a,' 26',0x0d,0x0a,' 27',0x0d,0x0a,' 28',0x0d,0x0a,' 29',0x0d,0x0a,' 30',0x0d,0x0a,' 31',0x0d,0x0a,' 32',0x0d,0x0a,' 33',0x0d,0x0a,' 34',0x0d,0x0a,' 35',0x0d,0x0a,' 36',0x0d,0x0a,' 37',0x0d,0x0a,' 38',0x0d,0x0a,' 39',0x0d,0x0a,' 40',0x0d,0x0a,' 41',0x0d,0x0a,' 42',0x0d,0x0a,' 43',0x0d,0x0a,' 44',0x0d,0x0a,' 45',0x0d,0x0a,' 46',0x0d,0x0a,' 47',0x0d,0x0a,' 48',0x0d,0x0a,' 49',0x0d,0x0a,' 50',0x0d,0x0a,' 51',0x0d,0x0a,' 52',0x0d,0x0a,' 53',0x0d,0x0a,' 54',0x0d,0x0a,' 55',0x0d,0x0a,' 56',0x0d,0x0a,' 57',0x0d,0x0a,' 58',0x0d,0x0a,' 59',0x0d,0x0a,' 60',0x0d,0x0a,' 61',0x0d,0x0a,' 62',0x0d,0x0a,' 63',0x0d,0x0a,' 64',0x0d,0x0a,' 65',0x0d,0x0a,' 66',0x0d,0x0a,' 67',0x0d,0x0a,' 68',0x0d,0x0a,' 69',0x0d,0x0a,' 70',0x0d,0x0a,' 71',0x0d,0x0a,' 72',0x0d,0x0a,' 73',0x0d,0x0a,' 74',0x0d,0x0a,' 75',0x0d,0x0a,' 76',0x0d,0x0a,' 77',0x0d,0x0a,' 78',0x0d,0x0a,' 79',0x0d,0x0a,' 80',0x0d,0x0a,' 81',0x0d,0x0a,' 82',0x0d,0x0a,' 83',0x0d,0x0a,' 84',0x0d,0x0a,' 85',0x0d,0x0a,' 86',0x0d,0x0a,' 87',0x0d,0x0a,' 88',0x0d,0x0a,' 89',0x0d,0x0a,' 90',0x0d,0x0a,' 91',0x0d,0x0a,' 92',0x0d,0x0a,' 93',0x0d,0x0a,' 94',0x0d,0x0a,' 95',0x0d,0x0a,' 96',0x0d,0x0a,' 97',0x0d,0x0a,' 98',0x0d,0x0a,' 99',0x0d,0x0a,'100',0x0d,0x0a

Name: Anonymous 2011-09-14 4:31

>>3
0x0d,0x0a
vomitchan.svg

Name: Anonymous 2011-09-14 4:35

>>4
Hahaha wow, that was careless of me.

Name: Anonymous 2011-09-14 5:07

>>4,5
Explain plox.

Name: Anonymous 2011-09-14 5:08

>>6
0x0d, 0x0a is equivalent to \r\n, the newline in Windows.
The code is for Linux. Newline in linux is just \n, or 0x0a.

Name: Anonymous 2011-09-14 5:14

Differentiating text streams from binary streams is bad, and you should all feel bad for giving in to this jewish practice.

Name: Anonymous 2011-09-14 5:15

>>7
Thanks.

Name: Anonymous 2011-09-14 5:17

Does Linux's write system call even handle things like '\n'?

Name: Anonymous 2011-09-14 5:22

>>10
Nope. That's why god made printf.

Name: Anonymous 2011-09-14 5:33

>>10

I believe that the write system call is only concerned with transferring an array of bytes to a file, and it doesn't have any idea what the data should represent. I think it is up to the program reading the text, how they want new lines to look like in binary, and they'll have their own expectations.

Name: Anonymous 2011-09-14 6:01

#include <stdio.h>

int main()
{
    char* s[4] = { "%d\n", "Fizz\n", "Buzz\n", "FizzBuzz\n" };
    int i = 0;
    while(++i <= 100)
        printf(s[(i % 3 == 0) | ((i % 5 == 0) << 1)], i);
}

Name: Anonymous 2011-09-14 7:28

>>13
Simple, but clever.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List