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

FIZZ MOTHERFUCKING BUZZ

Name: FIZ. Z. MCBUZZMASTER 2012-03-16 18:52

Write FIZZBUZZ in the most convoluted way you can think of.

Rules:
1. Your fizzbuzz implementation must work
2. Convolution =/= obfuscation: your code should be legible but should either work in a stupid way or be hard to understand (but NOT to read! that's too easy)
3. No statements with no effect (I mean like sticking "i + 1;" in the middle of a C function, not side-effects - functional languages are fine too).

Mine:
#!/usr/bin/env python

import socket
import sys

HOST = "127.0.0.1"
PORT = 9001

def client(n):
    global HOST, PORT
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((HOST, PORT))
    while n > 0:
        sock.send(str(n))
        data = sock.recv(20)
        sys.stdout.write("%02d: %s" % (n, data))
        n -= 1
    sock.close()

def server():
    global HOST, PORT
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.bind((HOST, PORT))
    sock.listen(1)
    while True:
        conn, addr = sock.accept()
        conn.setblocking(1)
        while True:
            i = 0
            try:
                i = int(conn.recv(20))
            except:
                break
            s = ""
            if (i % 3) == 0:
                s += "fizz"
            if (i % 5) == 0:
                s += "buzz"
            conn.send(s + "\n")
            if i == 0:
                break
        conn.close()

if __name__ == '__main__':
    if len(sys.argv) < 2:
        print("Usage: %s <client|server> [number]" % sys.argv[0])
        exit(1)
    if sys.argv[1] == "client":
        if len(sys.argv) < 3:
            print("Usage: %s <client|server> [number]" % sys.argv[0])
            exit(1)
        client(int(sys.argv[2]))
    elif sys.argv[1] == "server":
        server()
    else:
        print("Usage: %s <client|server> [number]" % sys.argv[0])
        exit(1)

Name: Anonymous 2012-03-16 22:18

Fizzbuzz in GPVM assembly:

    mov 0 acc

.fz_loop:
    cmp acc 100
    jmg .fz_out

    mov acc %gp12
    mod 3 %gp12
    cmp %gp12 0
    jme .fz_fizz
    push acc
    push "%d"
    call printf
    goto .fz_done
.fz_fizz:
    push "fizz"
    call put
    mov acc %gp12
    mod 5 %gp12
    cmp %gp12 0
    jme .fz_buzz
    goto .fz_done
.fz_buzz:
    push "buzz"
    call put
    goto .fz_done

.fz_done:
    push "\n"
    call put
    inc acc
    goto .fz_loop
.fz_out:
    die

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