0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Braincrash by QPython

0
Last updated at Posted at 2015-07-20
braincrash.py
from __future__ import print_function
from sys import stdin,stdout
from brainfuck import Brainfuck
from brainfuck import op
class Braincrash(Brainfuck):
    def __init__(s,OPs="><+-.,[]|&~^",size=30000):
        Brainfuck.__init__(s,OPs,size)
    def const(s,OPs):
        Brainfuck.const(s,OPs)
        s.opDic[OPs[8]]=opOr # op |
        s.opDic[OPs[9]]=opAnd # op &
        s.opDic[OPs[10]]=opNot # op ~
        s.opDic[OPs[11]]=opXor # op ^
    def run(s,limit=1000,out=stdout):
        Brainfuck.run(s,"Hello, world!",limit,out)
        while s.pt<len(s.mem) and s.mem[s.pt] != 0:
            out.write(chr(s.mem[s.pt]))
            s.pt+=1
# end class
class opOr(op):
    def do(s,bf):
        bf.mem[bf.pt]|=bf.mem[bf.pt+1]
        bf.pt+=1
        bf.pc+=1
# end class
class opAnd(op):
    def do(s,bf):
        bf.mem[bf.pt]&=bf.mem[bf.pt+1]
        bf.pt+=1
        bf.pc+=1
# end class
class opNot(op):
    offset = int("1"*8,2)
    def do(s,bf):
        bf.mem[bf.pt]^=s.offset
        bf.pc+=1
# end class
class opXor(op):
    def do(s,bf):
        bf.mem[bf.pt]^=bf.mem[bf.pt+1]
        bf.pt+=1
        bf.pc+=1
# end class
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?