In Brainfuck loops continue until they finish an iteration on a NULL cell. This means it is easy to move over a variable number of cells as long as there is a NULL cell to end on, for example a NULL terminated string:
> //NULL anchor
+ //!NULL anchor
[>,] //takes NULL terminated string input
<
[<] //returns to the NULL anchor
>
[>.] //prints the string
However what about the opposite?
Meaning a variable length "gap" of NULLs with non-NULL cells on each end:
[a][0][0][0][b]
A "brainfuck glider" ([>]
) cannot traverse over NULL cells and there is no "not loop" which would terminate on non-NULL cells instead.
I have tried an "incrementing glider" ([>+]
) but it obviously just travels forever...
Is this even possible?
This isn't too hard. Assume we have at least two zeroes to begin with:
+[->+>[<-]<]>>
This leaves the pointer at the first nonzero.
Also worth noting, if you want to look for a specific value--say, a 4:
----[++++>----]++++