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

/prog/ random code challenge

Name: Anonymous 2011-03-07 18:36

Write a program that generates random programming code.

Name: Anonymous 2011-03-10 5:06

from random import randint, choice

nest = 0
code = ''

for i in range(randint(2, 40)):
    ch = choice('-+<>[],.')
    if ch == ']':
        if nest == 0:
            continue
        else:
            nest -= 1
    elif ch == '[':
        nest += 1
    rep = randint(1, 4) if ch in '<>' else 1
    code += ch * rep

print code + nest * ']'


Brainfuck code. Always errorless, but not always halting. (+[] is an infinite loop)

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