Hello again, So, I'm trying to work out a problem where there are 6 symbols in a string (A, B, 0, 1, [, ]). The brackets always have to face each other in the string but they can be nested. There are some rules, most of which I have down, but when I get to the part that requires the brackets, I get confused as to how python might handle them efficiently. The main rules are that 'A' cannot be adjacent to '0' or another 'A', 'B' cannot be adjacent to '1' or another 'B' and this is true through the brackets as well. 'A' is "stronger" than '0' and 'B' is "stronger" than '1'... So, a string like 'AA001B001A' becomes 'AB001A' This is easily achieved with the replace method. However, it gets more complicated when the brackets are introduced and this is where I need help.
Also, the symbols inside the brackets are treated like rotating stacks, so, if A[001], then A[100], and if B[A[100]B0] then B[A[100]B] as the 'A' is considered adjacent to the '0'
so how can str='A[A[001]BB1A10]11BA10' become str=A[1A[100]BA]BA10 ?? or rather, how can any string in the first form become a well formed string given those rules? It seems a bit complicated for just the replace method.
Here is the code I have so far:
str='A[A[001]BB1A10]11BA10'
while '0A' in str:
str=str.replace('0A', 'A')
while 'A0' in str:
str=str.replace('A0', 'A')
while '1B' in str:
str=str.replace('1B', 'B')
while 'B1' in str:
str=str.replace('B1', 'B')
while 'BB' in str:
str=str.replace('BB', 'B')
while 'AA' in str:
str=str.replace('AA', 'A')
TIA!
-jmi