def eval_bf(self): """ Runs the brainfuck code. """ while self.pc < len(self.code): if ms.microseconds() - self.duration > 500: return instruction = self.code[self.pc] self.instruction_set[instruction]() self.pc += 1
def __init__(self, code=None, input_=None): """ Initializes i/o, pointer and tape. """ # define instruction set self.instruction_set = { '>': self.gt, '<': self.lt, '+': self.pls, '-': self.min, '.': self.dot, ',': self.comma, '[': self.lbracket, ']': self.rbracket } # simulate cells with a list self.tape = [0] * (2**15) # set the data pointer self.ptr = 0 # set up stack to match brackets self.bracket_stack = [] # set program counter self.pc = 0 # initialize input buffer and output buffer self.input = input_ self.input_counter = 0 self.output = [] # makes code a class variable if code: self.code = code else: self.code = list(sys.argv[1]) # run the code self.duration = ms.microseconds() self.eval_bf() self.duration = ms.microseconds() - self.duration
def __init__(self, code=None, input_=None): """ Initializes i/o, pointer and tape. """ # define instruction set self.instruction_set = {'>': self.gt, '<': self.lt, '+': self.pls, '-': self.min, '.': self.dot, ',': self.comma, '[': self.lbracket, ']': self.rbracket} # simulate cells with a list self.tape = [0] * (2 ** 15) # set the data pointer self.ptr = 0 # set up stack to match brackets self.bracket_stack = [] # set program counter self.pc = 0 # initialize input buffer and output buffer self.input = input_ self.input_counter = 0 self.output = [] # makes code a class variable if code: self.code = code else: self.code = list(sys.argv[1]) # run the code self.duration = ms.microseconds() self.eval_bf() self.duration = ms.microseconds() - self.duration
def __init__(self, pop_size): self.duration = ms.microseconds() self.evolve(pop_size) self.duration = ms.microseconds() - self.time print("duration:", self.time / 1000000, " seconds")