Brainfuck Interpreter - problem with interpretation

Back to General discussions forum

Norbiox     2017-07-15 16:56:24

I actually asked about it earlier but nobody answer it so...

Hello, I'm trying to write this BF interpreter, but probably I can't see something. Everytime when I'm testing my interpreter it returns 3 numbers, not as many as it's expected. So I've counted those '<' and '>' marks in test data to check if pointer can be bigger than 2 and I see that is impossible. This function helped me to count marks and max data pointer:

def checkPointerMovers():
    data = input()
    [left, right] = [0,0]
    max_pointer = 0
    for mark in data:
        if mark == '<':
            left += 1
        elif mark == '>':
            right += 1
        if right - left > max_pointer:
            max_pointer = right - left
    print(left,right, max_pointer)

Except that I'm missing something what is increasing data pointer too. Could anybody help, please?

goto     2017-07-15 19:00:14

I'm not very familiar with python, but your code seems to generate correct answer except that it's not separeted with spaces. I.e for answer: 12 17 1 28 3 13 0 21 21 9 0 9 your code output is: 1217128313021219090 9 24

Norbiox     2017-07-19 09:14:24

For loop checks each char in input() and increasing left or right if current char is < or >. Nevermind, I got the problem. My interpreter forgets to print value everytime when it meets ':' and print only final values of all cells.

MULTIVAC     2020-01-27 20:45:13
User avatar

its no running, for example print("hola")

Rodion (admin)     2020-01-28 15:05:24
User avatar

Hi Friend! Sorry, but I don't understand - what not running?

Please login and solve 5 problems to be able to post at forum