From 5c03c766def1373774ce92af3b2ed5399bd71967 Mon Sep 17 00:00:00 2001 From: Pawel Felcyn Date: Sat, 11 Nov 2023 20:11:16 +0100 Subject: [PATCH] b02 --- TaskB02/fsa_description.arg | 11 +++++++++++ TaskB02/run.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 TaskB02/fsa_description.arg create mode 100644 TaskB02/run.py diff --git a/TaskB02/fsa_description.arg b/TaskB02/fsa_description.arg new file mode 100644 index 0000000..b863b6c --- /dev/null +++ b/TaskB02/fsa_description.arg @@ -0,0 +1,11 @@ +0 4 0 +4 4 1 +4 4 0 +0 1 1 +1 4 1 +1 2 0 +2 3 1 +2 3 0 +3 3 1 +3 2 0 +2 \ No newline at end of file diff --git a/TaskB02/run.py b/TaskB02/run.py new file mode 100644 index 0000000..c314d29 --- /dev/null +++ b/TaskB02/run.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +import pandas as pd +import os + +def automat_fun(recursive_df: pd.DataFrame): + first_row = recursive_df.iloc[0] + recursive_df = recursive_df.iloc[1:,:] + return lambda char, state: first_row[1] if state == first_row[0] and char == first_row[2] else automat_fun(recursive_df)(char, state) + +def create_automat_from_file(file_path: str): + df = pd.read_csv(file_path, sep=' ', header=None) + accept_state = df.tail(1).iloc[0, 0] + df = df.iloc[:-1,:] + return accept_state, automat_fun(df) + +file_path = os.path.join(os.path.dirname(__file__), 'fsa_description.arg') +accept_state, automat_function = create_automat_from_file(file_path) + +txt = input('Write binary sequence: ') + +while txt != 'exit': + state = 0 + for c in txt: + if (c == '\n'): + break + state = automat_function(int(c), state) + print('YES' if state == accept_state else "NO") + txt = input('Write binary sequence: ') \ No newline at end of file