'hm'
This commit is contained in:
parent
69fa21a135
commit
c78c8da1e0
11
TaskB01/run
11
TaskB01/run
@ -35,21 +35,22 @@ class automata:
|
||||
def test_string(self, text):
|
||||
self.state = ['0']
|
||||
text = text.replace('\n', '')
|
||||
# for all values in text
|
||||
for i in text:
|
||||
# for all actual states
|
||||
for q in self.state:
|
||||
self.state = self.get_node_transition(q, i)
|
||||
# move state to its transition
|
||||
q = self.get_node_transition(q, i)
|
||||
if not self.state:
|
||||
return False
|
||||
return self.check_if_accepted()
|
||||
|
||||
# check if there is common part between states of automata and accepting states
|
||||
def check_if_accepted(self):
|
||||
return not set(self.state).isdisjoint(self.accepting_states)
|
||||
|
||||
def get_node_transition(self, q, i):
|
||||
self.storage[q]
|
||||
if i[0] == query:
|
||||
return i[1]
|
||||
return []
|
||||
return [] if not self.storage[q][i] else return self.storage[q][i]
|
||||
|
||||
|
||||
auto = automata()
|
||||
|
Loading…
Reference in New Issue
Block a user