Solution to last weeks HW ( Slide 2)
Solution to Problem on Slide 3.
Solution to Homework Problem on slide 4:
def do_op(value, op):
if 'LS' in op:
shift = int(op[-1])
value = value[shift:] + '#' * shift
elif 'RS' in op:
shift = int(op[-1])
value = '#' * shift + value[:-shift]
elif 'LC' in op:
shift = int(op[-1])
value = value[shift:] + value[:shift]
elif 'RC' in op:
shift = int(op[-1])
value = value[-shift:] + value[:-shift]
else:
start = int(op[-4])-1
length = int(op[-3])
shift = int(op[-2])
left = (op[-1] == 'L')
if left:
value = value[:start] +value[start + shift:start + length] + value[start:start + shift]+value[start+length:]
else:
value = value[:start] +value[start + length - 1 - shift:start +length] + value[start:start + length - 1 -shift]+value[start+length:]
return value
ops = input().split('/')
ops, val = ops[:-1], ops[-1]
for op in ops:
# print(val)
val = do_op(val, op)
print(val)