[Community Puzzle] What the Brainfuck!

Hi, love the turing machine simulator! It was a bit unclear tho as to how the bracket pairing works, with regards to nested brackets. I was under the understanding that the brackets would pair with whatever other bracket came before or after, not that they were paired together from the start. I also struggled with whether a single opening bracket could have multiple closing brackets for the same reason.

I think the problem description should list that each opening bracket will have EXACTLY ONE closing bracket. That would make it more clear and easier to understand.

The statement contains the following note:

Note: The [ and ] commands always come in pairs, and in case of nested [] the first [ always correspond to the last ].

Does that more or less carry the meaning of what you’ve suggested to add? I mean if they come in pairs, each opening bracket will most certainly have exactly one closing bracket, right?

1 Like

Pierre has a good response for debugging.

I suggest you consolidate the instructions into one line of valid characters instead of jumping between line to line.
It’ll eliminate bugs that you don’t really see in an obvious way that you do see if you make everything one dimensional.

I feel compelled to leave some feedback to this puzzle:

Loved it!

I have long been curious about the brainfuck language and thus was really happy with this opportunity to learn about it. I was expecting it to be much more complicated. And when I still had an error in the code and had to analyse the command string and finally realized that the brackets are used to construct loops … loved it!


1 Like


I have exactly the same issue, difficult to figure out the issue here…

Could anyone help me by any specific test code or code check ?


You may create custom cases as follows, and one of the combinations is the 6th validator (Incorrect value) itself:

L = 1
1 ≤ S ≤ 9
N = 0
program consists of one character (i.e. > or < or + or - or . or , or [ or ]) only
no input to the said program

INCORRECT VALUE (valid for that validator, or maybe for some of the input combinations)

When you say only one character you confirm the ‘.’ for print is excluded?
If my understanding is right the error ‘INCORRECT VALUE’ can be prompt only if a print is required by one ‘.’ in the code. So testing with the dot (as it is the only code based on your indication, it is printing ? as 0 is ‘NUL’ in ASCII table. trying to change the min value to eclude the 32 first values, it doesn’t suppress the validator fail.
Could you confirm my understanding ?

the error ‘INCORRECT VALUE’ can be prompt only if a print is required by one ‘.’ in the code.

If you mean “output” when you type “prompt”, then nope, your statement is wrong. The statement states:

In some cases, errors might be encountered. When this happens you have to stop the execution of the program and print the correct error message

To my understanding, the ASCII code of range occurs only proceeding to its call.
So the value of the cell shall be checked to be lower than 256 at the moment of its affectation / incrementation ?

The statement states:

An array of S one byte cells initialized to 0, and indexed from 0.

“INCORRECT VALUE” if after an operation the value of a cell becomes negative or higher than 255.

So, all cell values are correct at the beginning, and only after an operation the cell values should be checked to see whether any becomes “incorrect”.

Ok it works thanks.