Rozwiązania zadań z automatow

This commit is contained in:
Aleksander Misztal 2020-01-25 10:59:27 +01:00
parent 2b1dde2c99
commit b74810884c
4 changed files with 60 additions and 0 deletions

5
automata/Task201.py Normal file
View File

@ -0,0 +1,5 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
def is_initial_state_a_final_one(automaton):
return automaton.is_final_state(automaton.get_initial_state())

13
automata/Task202.py Normal file
View File

@ -0,0 +1,13 @@
#!/usr/bin/python2
# -*- coding: utf-8 -*-
"""
Rozwiązanie zadania 202
"""
def get_number_of_final_states(automaton):
counter = 0
for state in range(automaton.get_number_of_states()):
if automaton.is_final_state(state):
counter += 1
return counter

28
automata/Task203.py Normal file
View File

@ -0,0 +1,28 @@
#!/usr/bin/python2
# -*- coding: utf-8 -*-
"""
Rozwiązanie zadania 203
"""
# from deterministic_automaton import DeterministicAutomaton
def get_number_of_transitions(automaton, symbol):
counter = 0
for state in range(automaton.get_number_of_states()):
# print state, symbol, automaton.get_target_state(state, symbol)
if automaton.get_target_state(state, symbol) != None:
counter += 1
# print counter
return counter
# if __name__ == '__main__':
# automaton = DeterministicAutomaton()
# state_a = automaton.add_state()
# state_b = automaton.add_state()
# state_c = automaton.add_state()
# automaton.mark_as_initial(state_b)
# automaton.mark_as_final(state_a)
# automaton.add_transition(state_b, 'b', state_a)
# automaton.add_transition(state_a, 'b', state_b)
# automaton.add_transition(state_c, 'b', state_a)
# get_number_of_transitions(automaton, 'a')

14
automata/Task204.py Normal file
View File

@ -0,0 +1,14 @@
#!/usr/bin/python2
# -*- coding: utf-8 -*-
"""
Rozwiązanie zadania 204
"""
def get_number_of_loops(automaton, symbol):
counter = 0
for state in range(automaton.get_number_of_states()):
# print state, symbol, automaton.get_target_state(state, symbol)
if automaton.get_target_state(state, symbol) == state:
counter += 1
# print counter
return counter