[Community Puzzle] What the Brainfuck!

Mmm… more like a queue, no?

There is a bug in the automatically generated code in Python 3:

l, s, i = [int(i) for i in input().split()]
for i in range(l):
    r = input()
for i in range(i):
    c = int(input())

the variable i gets reassigned in the for-loop. After the first for-loop the value of i is equal to l-1, and not the value it should have from l, s, i = [int(i) for i in input().split()].

This leads to errors.

You’re right. I named it I (uppercase), and that’s OK for some languages, but it seems that the stub generator set the variables names to lowercase for Python, I don’t know why…
I gonna change this variable name to avoid problems…

EDIT: Changes done.

2 Likes

Hello,
All the tests are turning green but when I submit my code, the “Syntax Error” doesn’t turn green. I’m wondering why.
In my code I’m just checking numbers of opening and closing brackets and comparing them, if they differ I print “SYNTAX ERROR” before printing anything else. What am I doing wrong ?

I found the solution, nevermind :slightly_smiling_face: . I was trying to create pairs of brackets just before verifying numbers of brackets. And I was not shutting down the program correctly.

Great puzzle, I enjoyed it a lot :grinning:

1 Like

Having great fun making an Intel x64 cross-compiler rather than an interpreter… It compiles the BF source-code into x64 Machine Code, relocates this buffer into a Code Section, marks the memory executable and then executes it natively as a function.

Trying to be clever, I optimised runs of ++++'s and - - - -'s so they’d compile to …

CMP BYTE [r12], 255-count
JA error_overflow
ADD [r12], count

or

CMP BYTE [r12], count
JB error_underflow
SUB [r12], count

… and when the count is >256 I compile to an unconditional “JMP error_overflow,” instead,

But now I’m worried that the wording of the description might not permit this : /

Would I be right in assuming that a BF program that produces an error during its runtime, outputs ONLY the error - regardless of whether any ‘dot symbols’ have already been encountered?

If not, I’m going to need a different strategy : /

Anyone?

NM, it works! I certainly made that harder than it needed to be, LOL : ))))))

Honestly loved this puzzle! Should make another one for emoji language!

Yeah, this was a fun puzzle. Many happy memories : )
Have you seen >this< one, Parsons ???

It’s a little bit more involved, but it’s actually not too bad. It’s a good follow-up to the BF Interpreter : )

Hi all, I’ve got 100% test validated, but failing for the 6th validation final Incorrect Value, can please anyone provide me the input ?
Thanks in advance

You can send me your code in private, I’ll send back what’s wrong.

Very nice puzzle. A pleasure to solve and great learning. I gave you a 5/5

Very small typo I wanted to point out:
You wrote “on a a value corresponding to no printable ASCII characters” – that has an extra “a” in it.

2 Likes

Fixed, thanks for reporting.

2 Likes

Hi everyone, this puzzle is really fun but I can’t figure out how the inputs must be taken into account.
Could anyone please explain it to me?
I solved solution 1 & 2 because there is no input and am stuck on solution 3 :’(

After some research, I understand that 4 and 9 are inputs stored in the array.
I still can’t figure out how to use them.
I understood that the ‘,’ character puts 11111111 (so 255) in the array so after the 2nd ‘,’ the array should look like this:
255 | 255 | 57 | 52 (or 52 | 57)
I have tried many things and no result makes sense, I still need some help :face_with_diagonal_mouth:

Hey @abbecool ! I think you are overthinking the problem. ^^
You get N lines of inputs, one number per line. When you encounter a ‘,’ in the brainfuck programm, you simply read the next input line and put the number in the array cell currently pointed. That’s all.
So if the next input line is “4” and the pointed cell is the first one, when you encounter a ‘,’ you put 4 in that cell.

12 Likes

Oh man thank you for your reply! I just didn’t properly understand the comma:
<< , accept a positive one byte integer as input and store it in the pointed cell. >>
I thought a positive one byte integer was 11111111…
Thank you again!

Hello everyone,

I passed most of the tests but the 3rd and 6th still fail.

I don’t know why, but the BF code wants to go backward below the limit.
Here is all the steps:

line 0 ptr 0 val 0 instr ,
line 1 ptr 0 val 4 instr >
line 2 ptr 1 val 0 instr ,
line 3 ptr 1 val 9 instr >
line 4 ptr 2 val 0 instr <
line 5 ptr 1 val 9 instr [
line 6 ptr 1 val 9 instr <
line 7 ptr 0 val 4 instr [
line 8 ptr 0 val 4 instr >
line 9 ptr 1 val 9 instr >
line 10 ptr 2 val 0 instr +
line 11 ptr 2 val 1 instr >
line 12 ptr 3 val 0 instr +
line 13 ptr 3 val 1 instr <
line 14 ptr 2 val 1 instr <
line 15 ptr 1 val 9 instr <
line 16 ptr 0 val 4 instr -
line 17 ptr 0 val 3 instr ]
line 8 ptr 0 val 3 instr >
line 9 ptr 1 val 9 instr >
line 10 ptr 2 val 1 instr +
line 11 ptr 2 val 2 instr >
line 12 ptr 3 val 1 instr +
line 13 ptr 3 val 2 instr <
line 14 ptr 2 val 2 instr <
line 15 ptr 1 val 9 instr <
line 16 ptr 0 val 3 instr -
line 17 ptr 0 val 2 instr ]
line 8 ptr 0 val 2 instr >
line 9 ptr 1 val 9 instr >
line 10 ptr 2 val 2 instr +
line 11 ptr 2 val 3 instr >
line 12 ptr 3 val 2 instr +
line 13 ptr 3 val 3 instr <
line 14 ptr 2 val 3 instr <
line 15 ptr 1 val 9 instr <
line 16 ptr 0 val 2 instr -
line 17 ptr 0 val 1 instr ]
line 8 ptr 0 val 1 instr >
line 9 ptr 1 val 9 instr >
line 10 ptr 2 val 3 instr +
line 11 ptr 2 val 4 instr >
line 12 ptr 3 val 3 instr +
line 13 ptr 3 val 4 instr <
line 14 ptr 2 val 4 instr <
line 15 ptr 1 val 9 instr <
line 16 ptr 0 val 1 instr -
line 17 ptr 0 val 0 instr ]
line 18 ptr 0 val 0 instr >
line 19 ptr 1 val 9 instr >
line 20 ptr 2 val 4 instr >
line 21 ptr 3 val 4 instr [
line 22 ptr 3 val 4 instr <
line 23 ptr 2 val 4 instr <
line 24 ptr 1 val 9 instr <
line 25 ptr 0 val 0 instr +
line 26 ptr 0 val 1 instr >
line 27 ptr 1 val 9 instr >
line 28 ptr 2 val 4 instr >
line 29 ptr 3 val 4 instr -
line 30 ptr 3 val 3 instr ]
line 22 ptr 3 val 3 instr <
line 23 ptr 2 val 4 instr <
line 24 ptr 1 val 9 instr <
line 25 ptr 0 val 1 instr +
line 26 ptr 0 val 2 instr >
line 27 ptr 1 val 9 instr >
line 28 ptr 2 val 4 instr >
line 29 ptr 3 val 3 instr -
line 30 ptr 3 val 2 instr ]
line 22 ptr 3 val 2 instr <
line 23 ptr 2 val 4 instr <
line 24 ptr 1 val 9 instr <
line 25 ptr 0 val 2 instr +
line 26 ptr 0 val 3 instr >
line 27 ptr 1 val 9 instr >
line 28 ptr 2 val 4 instr >
line 29 ptr 3 val 2 instr -
line 30 ptr 3 val 1 instr ]
line 22 ptr 3 val 1 instr <
line 23 ptr 2 val 4 instr <
line 24 ptr 1 val 9 instr <
line 25 ptr 0 val 3 instr +
line 26 ptr 0 val 4 instr >
line 27 ptr 1 val 9 instr >
line 28 ptr 2 val 4 instr >
line 29 ptr 3 val 1 instr -
line 30 ptr 3 val 0 instr ]
line 31 ptr 3 val 0 instr <
line 32 ptr 2 val 4 instr <
line 33 ptr 1 val 9 instr -
line 34 ptr 1 val 8 instr ]
line 22 ptr 1 val 8 instr <
line 23 ptr 0 val 4 instr <
POINTER OUT OF BOUNDS
DEBUG [ 4, 8, 4, 0 ] pointerPosition: -1

I don’t know what’s going on.
Assuming all the tests are corrects, my code is wrong and I don’t know what should be the programm behaviour here.

Can anyone help me, please?

You have mentioned 2 tests, but have not specified which test the steps are related to. I’ll assume it’s for the 3rd test.

Near the end, after you arrive at line 34, you go to line 22. That is not correctly matching the brackets. You should go to line 6 instead:

          1         2         3
0123456789012345678901234567890123456789
,>,><[<[>>+>+<<<-]>>>[<<<+>>>-]<<-]>.

Yes, correct.

Thank you for your help, I’ll try to fix this !