I am trying to write a program (which I'm sure has been done before, just trying to challenge myself) that takes two user inputs per loop, one for the letter/number, and one to check if the user is done inputting (y/n), and then print the whole string. I know what I have so far isn't fantastic, but basically I start the loop, move the pointer up two (so there's a findable 0 value at the beginning), ask for the first and second inputs, set the next value to lowercase n, and am currently trying to figure out how to compare the values. I have tried to print values, which only appear to print after two inputs and then the program breaks.
Here is what I have so far:
+[>>[>].,>,>>++++++++++[<+++++++++++>-]<.[->-[>]<<].<[<]<-]
If it makes a difference, I am using a homemade brainfuck interpreter, which may have some imperfections:
def brainfuck(code):
array = [0]
pointer = 0
i = 0
while(i < len(code)):
if(code[i] == '<'):
if(i != 0):
if(pointer != 0):
pointer -= 1
elif(code[i] == '>'):
pointer += 1
if(len(array) <= pointer):
array.append(0)
elif(code[i] == '+'):
array[pointer] += 1
elif(code[i] == '-'):
if(array[pointer] > 0):
array[pointer] -= 1
elif(code[i] == '.'):
print(pointer,chr(array[pointer]))
elif(code[i] == ','):
x = input('Input:')
try:
array[pointer] = int(x)
except ValueError:
array[pointer] = ord(x)
elif(code[i] == '['):
if(array[pointer] == 0):
openBraces = 1
while(openBraces > 0):
i += 1
if(code[i] == '['):
openBraces += 1
elif(code[i] == ']'):
openBraces -= 1
elif(code[i] == ']'):
openBraces = 1
while(openBraces > 0):
i -= 1
if(code[i] == '['):
openBraces -= 1
elif(code[i] == ']'):
openBraces += 1
i -= 1
i += 1
I made something like this a long time ago, should do the trick (if I remember right)
The comments show what memory looks like before each line and they may be structured a bit weirdly in order to avoid using symbols which would be considered as brainfuck by the interpreter. Values in the memory are separated by apostrophes and brackets are used to show which position in the memory the pointer is at.
Make sure to have the value you want to compare the input to in the second position in the memory and to move the pointer back to the first position before implementing this code.
I'm sorry that I didn't read through your interpreter, but I assume that it works.
Hope this helps!