From 7720a2a6217423db49e41e51d7258d113d639e27 Mon Sep 17 00:00:00 2001 From: Maxim Slipenko <36362599+Maks1mS@users.noreply.github.com> Date: Mon, 20 Sep 2021 20:13:50 +0300 Subject: [PATCH] fix direction --- turinglab/emulator.py | 9 +++++++-- turinglab/input.py | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/turinglab/emulator.py b/turinglab/emulator.py index aae7309..2a090a8 100644 --- a/turinglab/emulator.py +++ b/turinglab/emulator.py @@ -1,5 +1,11 @@ from collections import defaultdict +DIRECTIONS = { + '>': 1, + '<': -1, + '.': 0 +} + class Emulator(): ''' @@ -28,7 +34,7 @@ class Emulator(): self.tape[self.head] = symbol self.current_state = state - self.head += 1 if direction == '>' else -1 + self.head += DIRECTIONS[direction] self.tape[self.head] = self.tape[self.head] @@ -45,5 +51,4 @@ class Emulator(): return [self.head, self.current_state, defaultdict(lambda: self.blank_symbol, self.tape)] - diff --git a/turinglab/input.py b/turinglab/input.py index fa35ffc..53ed842 100644 --- a/turinglab/input.py +++ b/turinglab/input.py @@ -1,5 +1,5 @@ import csv -import pprint +import re def from_tur(filename): f = open(filename, "rb") @@ -65,7 +65,7 @@ def from_file(filename: str): if not action: continue - new_symbol, direction, new_state = list(action) + new_symbol, direction, new_state = re.split('([<|>|.])', action) if new_symbol == "_": new_symbol = 'λ'