def brainfuck(code):
    tape = [0] * 30000
    ptr = 0
    mov = 0
    ip = 0
    output = []

    bracket_map = {}
    stack = []
    for i, c in enumerate(code):
        if c == "=":
            stack.append(i)
        elif c == ";":
            j = stack.pop()
            bracket_map[i] = j
            bracket_map[j] = i

    while ip < len(code):
        c = code[ip]

        if c == "h":
            ptr = (ptr + 1) % 30000
        elif c == "d":
            ptr = (ptr - 1) % 30000
        elif c == "a":
            tape[ptr] = (tape[ptr] + 1) % 256
        elif c == "e":
            tape[ptr] = (tape[ptr] - 1) % 256
        elif c == "i":
            tape[ptr] = (tape[ptr] * 2) % 256
        elif c == "o":
            tape[ptr] = (tape[ptr] // 2) % 256   # ← 修正点
        elif c == ".":
            output.append(chr(tape[ptr]))
        elif c == "x":
            if tape[ptr] != 0:
                mov = tape[ptr]
                tape[ptr] = 0
            else:
                tape[ptr] = mov
                mov = 0
        elif c == "y":
            tape[ptr] = (tape[ptr] + mov) % 256
            mov = 0
        elif c == "z":
            tape[ptr] = (tape[ptr] - mov) % 256
            mov = 0
        elif c == "=":
            if tape[ptr] == 0:
                ip = bracket_map[ip]
        elif c == ";":
            if tape[ptr] != 0:
                ip = bracket_map[ip]

        ip += 1

    return "".join(output)
print(brainfuck("aiiia = haaaaaaaade; h.aiiia = haaaaaaaade; heee."))

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: