Is it possible to Brainfuck interpreter by yourself?

Back to General discussions forum

qwerty     2025-04-03 12:52:13

In the statement of problem #86, one can see a funny sentence:

Do not be afraid - it is easier to write Brainfuck interpreter itself than to write Brainfuck problems

The fun fact is that writing Brainfuck interpreter is much harder than finding a problem for such interpreter.

Do any of you have a working interpreter, for example, for Mandelbrot set? I studied around hundred of CodeAbbey solutions, and there are no working solutions which output result before time limit exceeds...

The few working solutions on internet are outside of CodeAbbey.

And I myself did not got a working solution in a week, so I think that funny sentence quoted above must be removed from problem statement, it just doesn't make sense.

P.S. By the way - tests like mandel.b can be easily generated by transpiler, for example here is one in Python

qwerty     2025-04-03 13:40:19

Sorry, the topic name should be "Is it possible to write Brainfuck interpreter by yourself?"

ecolog_veteran     2025-04-03 13:47:59
User avatar

If we are talking about an efficient implementation of BF interpreter then yes, it can be hard to write.

Then again, I don't suppose that the goal of problem 86 is to make a fast interpreter.

Additionally, you have to consider that the interpreted nature of the BF entails some overhead.

I may have misunderstood what you meant though.

gardengnome     2025-04-03 13:56:54
User avatar

In my opinion, it is easier to write a working, not necessarily efficient, BF interpreter than writing solutions for problems in BF. So I agree with the key message of the 'funny sentence'. The hint is in the name. :)

qwerty     2025-04-03 15:29:39

I may have misunderstood what you meant though

I meant an optimizing interpreter. For example, given code ;[-]: and input 999999999, an optimizing interpreter will output 0 in a blink of eye, but 99.9% solutions here won't output anything in years...

qwerty     2025-04-03 15:34:50

In my opinion, it is easier to write a working, not necessarily efficient, BF interpreter than writing solutions for problems in BF.

Sounds like you write solutions for Brainfuck problems by hand, but it is much easier to write a Brainfuck code generator and generate code automatically, than to write code by hand or write a good Brainfuck interpreter.

gardengnome     2025-04-03 17:14:18
User avatar

Sounds like you write solutions for Brainfuck problems by hand: Correct, for me personally that was the spirit of the BF problems here on this site. And I am not planning to do any more BF problems any time soon. :) Also, I would argue that writing a good BF code generator might well be as challenging as writing a good BF interpreter.

ecolog_veteran     2025-04-03 17:30:32
User avatar

I meant an optimizing interpreter

Isn't an overkill for the task? It's a good challenge but not the point of the aforementioned problem.

For example, given code ;[-]: and input 999999999, an optimizing interpreter will output 0 in a blink of eye, but 99.9% solutions here won't output anything in years...

Hm, mine finished in a few seconds. Guess my solution goes into that 0.1%? :) Just kidding.

Sounds like you write solutions for Brainfuck problems by hand

I thought that was the point.

but it is much easier to write a Brainfuck code generator and generate code automatically

I actually thought about something similar. By that I mean making some sort of language that would compile into i4004 assembly.

ecolog_veteran     2025-04-03 17:31:28
User avatar

Quote blocks are so huge for some reason compared to the other text.

qwerty     2025-04-04 07:10:31

Hm, mine finished in a few seconds. Guess my solution goes into that 0.1%

I just did not type enough nines for C++, which is much faster than Python :)... But I think you got the idea.

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