Advertisement
Mancolo

Выполнение арифметических операций на машине Тьюринга

May 17th, 2023
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. def move_chars(input_string):
  2. tape = list(input_string)
  3. state = 'q1'
  4. position = 0
  5.  
  6. while state != 'qf':
  7. if state == 'q1':
  8. if tape[position] == 'a':
  9. tape.pop(position)
  10. tape.insert(0, 'a')
  11. position += 1
  12. elif tape[position] == 'b':
  13. position += 1
  14. if position == len(tape):
  15. state = 'qf'
  16.  
  17. return ''.join(tape)
  18.  
  19. # Пример использования
  20. input_string = 'abababa'
  21. result = move_chars(input_string)
  22. print(result)
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement