I am attempting to solve this riddle similar to the Wolf, goat and cabbage problem, and trying to represent it in a graph format (with nodes and edges representing all potential paths).
This is the problem:
2 circus families have got an act where one family, consisting of a mother, father and daughter, are on the left hand side of a flying trapeze and the other family, with two brothers and a sister, are on the right hand side of the flying trapeze. Each person begins by hanging from their own individual swing and there is an empty swing separating the two families as follows:
Mother, Father, Daughter, Empty, Sister, Younger Brother, Older Brother
It is only possible a person to swing from their swing to an empty swing that is either adjacent to their current swing or that is separated from their position by a single individual from either family. The aim of the trick is for both families to swap sides. No member of the family is allowed to swing backwards at any stage. What is the sequence of moves which will result in the trick being performed successfully?
I labelled the family on the left as family 'A' and the family on the right as 'B', and empty as 'É', and started with the first position, trying to graph all the possible permutations that could exist.
Right now I tried to do only the first possible move (moving to an adjacent empty swing), but I seem to be running into some technical problem I have no idea why it is.
I am trying to make the list of possible steps at each step.
This is what I have.
iC=['A','A','A','E','B','B','B']
newC=[]
for x in range(0,7):
if iC[x]=='E':
if iC[x-1]=='A' and iC[x+1]=='B':
iC[x-1]='E'
iC[x]='A'
newC.append(iC)
iC[x-1]='A'
iC[x]='B'
iC[x+1]='E'
newC.append(iC)
elif iC[x-1]=='A':
iC[x-1]='E'
iC[x]='A'
newC.append(iC)
elif iC[x+1]=='B':
iC[x+1]=='E'
iC[x]=='B'
newC.append(iC)
break
print(newC)
I am trying to append a new item into a new list but it changes the item instead. Could it because the append is in the if statement twice and just changes the appended item? Is there a more efficient way of doing this? Thanks any help would be appreciated :)