Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def move_chars(input_string):
- tape = list(input_string)
- state = 'q1'
- position = 0
- while state != 'qf':
- if state == 'q1':
- if tape[position] == 'a':
- tape.pop(position)
- tape.insert(0, 'a')
- position += 1
- elif tape[position] == 'b':
- position += 1
- if position == len(tape):
- state = 'qf'
- return ''.join(tape)
- # Пример использования
- input_string = 'abababa'
- result = move_chars(input_string)
- print(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement