From b74810884c2a8a8ff3078d8390d153e1471e3766 Mon Sep 17 00:00:00 2001 From: Aleksander Misztal Date: Sat, 25 Jan 2020 10:59:27 +0100 Subject: [PATCH] =?UTF-8?q?Rozwi=C4=85zania=20zada=C5=84=20z=20automatow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- automata/Task201.py | 5 +++++ automata/Task202.py | 13 +++++++++++++ automata/Task203.py | 28 ++++++++++++++++++++++++++++ automata/Task204.py | 14 ++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 automata/Task201.py create mode 100644 automata/Task202.py create mode 100644 automata/Task203.py create mode 100644 automata/Task204.py diff --git a/automata/Task201.py b/automata/Task201.py new file mode 100644 index 0000000..72e3916 --- /dev/null +++ b/automata/Task201.py @@ -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()) diff --git a/automata/Task202.py b/automata/Task202.py new file mode 100644 index 0000000..5127e09 --- /dev/null +++ b/automata/Task202.py @@ -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 diff --git a/automata/Task203.py b/automata/Task203.py new file mode 100644 index 0000000..693ada2 --- /dev/null +++ b/automata/Task203.py @@ -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') diff --git a/automata/Task204.py b/automata/Task204.py new file mode 100644 index 0000000..051c030 --- /dev/null +++ b/automata/Task204.py @@ -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