-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremoveDoubleMoves.py
39 lines (39 loc) · 1.75 KB
/
removeDoubleMoves.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def doubleMoveRemover(scramble):
newScr = []
newScrString = ""
scrSplit = scramble.split()
# go through all moves
for i in range(len(scrSplit)):
# if newScr contains already one element, check the properties of consecutive moves
if len(newScr) >= 1:
# newScr contains at least one element.
# check if the previous and current move are equal
if newScr[-1] == scrSplit[i]:
# e.g. R R or R' R'
# now find out whether they've got the ' or not by checking the length
if len(scrSplit[i]) == 1:
# just one character --> case (e.g.) R R
newScr.pop()
newScr.append(scrSplit[i]+"'")
else:
# it's the case when there's more than one char, so e.g. R' R'
newScr.pop()
newScr.append(scrSplit[i][0])
else:
# previous and current move are not equal
# check whether they are just a prime away from each other or completely
# different moves
if newScr[-1][0] == scrSplit[i][0]:
# first char is equal --> e.g. R' R --> don't add the new one, but
# remove the previous one, as they cancel out each other
newScr.pop()
else:
# completely different moves --> we can safely add the current move
newScr.append(scrSplit[i])
# there is no entry in newScr, so we can safely add the move as is
else:
newScr.append(scrSplit[i])
for move in newScr:
newScrString += move + " "
return newScrString
#print(doubleMoveRemover("R' R L L'"))