-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.py
18 lines (14 loc) · 882 Bytes
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import re
def simplify(string):
string = ' '.join([sub for sub in string.split(' ') if '(' not in sub])
string = string.replace('3', "'").replace('1', '')
string = re.sub('\s{2,}', ' ', (string + ' ').replace("''", '').replace("2'", '2').replace('(', '').replace(')', '').replace('\n', ' '))
prev_string = ''
while prev_string != string:
prev_string = string
for i in ('B', 'D', 'F', 'L', 'R', 'U'):
for pair in [(f"{i} {i} ", f"{i}2 "), (f"{i} {i}' ", ''), (f"{i} {i}2 ", f"{i}' "), (f"{i}' {i} ", ''), (f"{i}' {i}' ", f"{i}2 "), (f"{i}' {i}2 ", f"{i} "), (f"{i}2 {i} ", f"{i}' "), (f"{i}2 {i}' ", f"{i} "), (f"{i}2 {i}2 ", '')]:
string = string.replace(*pair)
return string.strip(' ')
def reverse(string):
return simplify(' '.join([char + "'" if char != '' else '' for char in string.split(' ')][::-1]))