fix direction
This commit is contained in:
parent
6a7b9201b7
commit
7720a2a621
@ -1,5 +1,11 @@
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
|
DIRECTIONS = {
|
||||||
|
'>': 1,
|
||||||
|
'<': -1,
|
||||||
|
'.': 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Emulator():
|
class Emulator():
|
||||||
'''
|
'''
|
||||||
@ -28,7 +34,7 @@ class Emulator():
|
|||||||
self.tape[self.head] = symbol
|
self.tape[self.head] = symbol
|
||||||
|
|
||||||
self.current_state = state
|
self.current_state = state
|
||||||
self.head += 1 if direction == '>' else -1
|
self.head += DIRECTIONS[direction]
|
||||||
|
|
||||||
self.tape[self.head] = self.tape[self.head]
|
self.tape[self.head] = self.tape[self.head]
|
||||||
|
|
||||||
@ -46,4 +52,3 @@ class Emulator():
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import csv
|
import csv
|
||||||
import pprint
|
import re
|
||||||
|
|
||||||
def from_tur(filename):
|
def from_tur(filename):
|
||||||
f = open(filename, "rb")
|
f = open(filename, "rb")
|
||||||
@ -65,7 +65,7 @@ def from_file(filename: str):
|
|||||||
if not action:
|
if not action:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
new_symbol, direction, new_state = list(action)
|
new_symbol, direction, new_state = re.split('([<|>|.])', action)
|
||||||
|
|
||||||
if new_symbol == "_":
|
if new_symbol == "_":
|
||||||
new_symbol = 'λ'
|
new_symbol = 'λ'
|
||||||
|
Loading…
Reference in New Issue
Block a user