Effective implementation of the while loop in the brain ***

I am having problems implementing the brainf *** collector for codegolf.se. I managed to load a string into memory to find its length, print lines n times, etc., but I don't seem to load only lowercase numbers into memory. So let's take the next cycle that does some magic. (Hash tags are debugging markers.)

#,#[>#<[<]<<#+#>>>[>]#,#]<[<] 

It starts with a pointer of 512 and writes the string as ascii values ​​to spots after 512


Now, if (for some reason) I want to cross out lowercase characters, it will look like this in psuedo BF.
 #,#[>#<[<]<<#+#>>>[>]#do{,(takes input and assigns it)} while(input>=96/*Go arbitrarily to the right for this implementation but make sure that the first non-lowercase number is stored at the index*/)# //Also be sure to zero out any temporary cells used <[<] 

Now my question is: how to implement such a while loop, using only spaces to the right of 512 as storage and freeing them later. For those interested in this , this is a problem I want to solve in branf ***.

+5
source share
1 answer

Your code can be simplified to

 ,[[<]<+>>[>],]<[<] 

( <<+>> is probably the result of using an online compiler that forgets cell 255)

and repeat to perform the output operation:

 >.[[<]<->>[>]<.>]<[<] 

If you want to use only empty cells in your path, you can do it. But you will need to set your own protocol to determine the next cell, for example, save each data cell with the next cell, indicating the distance to the next, as:

 [..., 104, 5, x, x, x, x, 108, 3, x, x, 102, 2...] [..., 104 , 5 , x, x, x, x, 108 , 3 , x, x, 102 , 2 ...] data pointer data pointer data pointer 

when x is some arbitrary value other than zero (otherwise you would use it). This implementation would be relative - a linked list, but note that it will be space and code more expensive .


Zeroing the cells , or, as you call it, cleaning them, you can do the same as you did [<] using [-] . this will reduce the value of the cell until it reaches 0, and then fails. You can iterate the line down when you are at the end and go back by clearing each cell until you hit the beginning ( 0 or another reserved number that you put there).

+1
source

All Articles