[Community Puzzle] What the Brainfuck!

https://www.codingame.com/training/medium/what-the-brainfuck

Send your feedback or ask for help here!

Created by @anon72424297,validated by @dbdr,@Zorg1 and @JBM.
If you have any issues, feel free to ping them.

IMPORTANT UPDATE:
After viewing the @JBM’s stream (Replay here), reading his post (Here), and talking with him and @Zorg1, I decided to make a few changes on the puzzle.
First, the two kinds of input errors were more constraining than interesting, and were more about the puzzle format constraints than real interpreter problems. (At least concerning the missing input one.). So I removed them, and so the corresponding tests and validators.
Secondly, the 3 remaining errors validators are the exact inverses of their corresponding tests. To avoid incomplete solutions to pass, and also to check the correct management of the errors priority, I added the “Multiple errors” test/validator.
Despite this changes, the already validated solutions which totally fulfilled the puzzle requirements are still valids.
All this changes are also indicated in the statement and on the publication page.

1 Like

Hi my code pass all the test but not the multiple errors validators.
What error does it check ?

i would think that there are many errors and that you did not stop at first error and output a wrong one…

My all test cases are running but validator showing error in “Syntax error” .what could go wrong ???

Make sure the error appears even if you don’t jump when reaching []

Hi nopnop1,

Hi my code pass all the test but not the multiple errors validators.
What error does it check ?

You must respect the order of priority of errors.
If there are multiple errors, you should check and return the error with the highest priority first.

Errors Priority Order :

  1. "SYNTAX ERROR"
  2. "POINTER OUT OF BOUNDS"
  3. "INCORRECT VALUE"
2 Likes

Hi,

When I run all test cases i fail the Multiple Errors test case because I ouput an INCORRECT VALUE firstly (However if that error didn’t exist the POINTER OUT OF BOUNDS would be found).

For whatever reason i submitted and I scored 100% having that test case failed.

Why does it happen?

FYI: In other submissions I hitted correctly the POINTER OUT OF BOUNDS correctly.

EDIT: Assuming that my program is correct i have the feeling that the statement of the problem has a small problem here:

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

I think it should state if the value of a cell becomes negative at the output time, that is, after “.” is read.

Hi nopnop1,

Hi my code pass all the test but not the multiple errors validators.
What error does it check ?

You must respect the order of priority of errors.
If there are multiple errors, you should check and return the error with the highest priority first.

Errors Priority Order :

  1. "SYNTAX ERROR"
  2. "POINTER OUT OF BOUNDS"
  3. "INCORRECT VALUE"

I have done it but it still doesn’t work; giving me some test value close to the validator would be great to help debugging

Hey.
The test and the validator about multiple errors are not the sames, and the errors order is different, so you can pass one and not the other if your error detection is not perfect.
And I’m not sure to understand what you mean about the output time… Can you explain ?

1 Like

You’re probably missing something about the error priority… Read the statement carefully. :slight_smile:

i have done it but i don’t know why it doesn’t work before

Thanks, i had a “silly” error (i didnt constrained my pointer correctly) which leaded to a confusing outcome. Thanks for your time. Nice and interesting problem.

2 Likes

Hi,
How is your test for this part ?
To confront your code, you can check test 7 and force the input to replace the only ‘[’ by a ‘]’ .
It helped me to fix my code (I had the same situation than you).

1 Like

Fun challenge. But I can’t stand it’s failing on one validator test. Can someone maybe steer me in the right direction?

It’s the one syntax error validator (i do pass all the tests).
What I do to build, and later validate (before main program runs) my bracketMap:

def buildBracketMap(inputLine):
    bracketPairs = []
    for idx, char in enumerate(inputLine):
        indent = 0 
        if char == "[":
            bracketPairs.append({'open' : idx})
            startIdx = idx
            for idx2, char2 in enumerate(inputLine[startIdx:]):
                if char2 == "[": indent +=1
                if char2 == "]" and indent != 0: indent -=1    
                if char2 == "]" and indent == 0:
                    bracketPairs[len(bracketPairs) -1]["closed"] = idx2 + startIdx
                    break            
    return bracketPairs


for bracket in bracketMap:
    if len(bracket) != 2:
        print("SYNTAX ERROR")
        exit(0) 
    if (inputLine.count('[') != len(bracketMap) or inputLine.count(']') != len(bracketMap)):
        print("SYNTAX ERROR")
        exit(0) 
    if bracket['closed']-bracket['open'] == 1:
        print("SYNTAX ERROR")
        exit(0) 

What am I missing?

What happens when there are no opening brackets?

Aiaiai, yes I didn’t know why I put this:

if (inputLine.count('[') != len(bracketMap) or inputLine.count(']') != len(bracketMap)):
    print("SYNTAX ERROR")
    exit(0) 

Inside the bracketMap loop, :face_with_hand_over_mouth:… thanks @RoboStac !

My Code passes all Testcases but fails in the final Syntax Error category. Is there any possibility to see the input which it fails against?

Edit:
Nevermind, I’ve found the mistake in my parser.

I think it would be valuable to explain the input list is a stack of inputs for the same program, I took ages to understand how wrong I was about the input treatment !

1 Like

I’m OK to clarify the statement if needed, but I don’t see what you mean…
The “Inputs” section states:

Line 1: Three integers L, S and I for the program line count, the needed array size and the inputs count.
Next L lines: A line of the Brainfuck program.
Next I lines: An integer input to the Brainfuck program.

It is not clear enough ?