From e87d5b53bde543dc5e4fdee17b42818108b3f8ad Mon Sep 17 00:00:00 2001 From: IgnBys Date: Wed, 1 Nov 2023 22:36:00 +0100 Subject: [PATCH 1/5] TaskB00 --- description.txt | 8 ++++++++ fsa_description.arg | 16 ++++++++++++++++ run.py | 29 +++++++++++++++++++++++++++++ test1.exp | 9 +++++++++ test1.in | 9 +++++++++ test1.out | 8 ++++++++ 6 files changed, 79 insertions(+) create mode 100644 description.txt create mode 100644 fsa_description.arg create mode 100644 run.py create mode 100644 test1.exp create mode 100644 test1.in create mode 100644 test1.out diff --git a/description.txt b/description.txt new file mode 100644 index 0000000..6ca4676 --- /dev/null +++ b/description.txt @@ -0,0 +1,8 @@ +Read a description of a deterministic finite-state automaton in the AT&T format +(without weights) from the file in the first argument. + +Read strings from the standard input. +If a string is accepted by the +automaton, write YES, otherwise- write NO. + +The program is invoked like this: ./run.py fsa_description.arg < test1.in > test1.out diff --git a/fsa_description.arg b/fsa_description.arg new file mode 100644 index 0000000..3505b65 --- /dev/null +++ b/fsa_description.arg @@ -0,0 +1,16 @@ +0 1 x +1 2 y +2 3 z +0 4 y +0 4 z +1 4 x +1 4 z +2 4 x +2 4 y +3 4 x +3 4 y +3 4 z +4 4 x +4 4 y +4 4 z +3 diff --git a/run.py b/run.py new file mode 100644 index 0000000..d0829a5 --- /dev/null +++ b/run.py @@ -0,0 +1,29 @@ +import sys +def write_answer(answer): + with open('test1.out', 'a') as file: + file.write(answer+'\n') +def find_next_position(position, character): + with open('fsa_description.arg', 'r') as readed_used_table: + for row_used_table in readed_used_table: + line = row_used_table.strip().split('\t') + if position == line[0] and character == line[2]: + return True,line[1] +# used_table = sys.argv[1] +# input_file = sys.argv[2] +with open('test1.out', 'w') as readed_output_file: + with open('test1.in', 'r') as readed_input_file: + for row_input_file in readed_input_file: + result = False + next_position = None + position = '0' + for character in row_input_file: + if character =='\n': + if position=='3': + write_answer('YES') + break + else: + write_answer('NO') + break + result, next_position = find_next_position(position,character) + if result == True: + position = next_position \ No newline at end of file diff --git a/test1.exp b/test1.exp new file mode 100644 index 0000000..ff99c7b --- /dev/null +++ b/test1.exp @@ -0,0 +1,9 @@ +NO +YES +NO +NO +NO +NO +NO +NO +NO \ No newline at end of file diff --git a/test1.in b/test1.in new file mode 100644 index 0000000..d82237e --- /dev/null +++ b/test1.in @@ -0,0 +1,9 @@ +xxyz +xyz +xy +zz +xxy +yzx + +x +xyzz diff --git a/test1.out b/test1.out new file mode 100644 index 0000000..680815f --- /dev/null +++ b/test1.out @@ -0,0 +1,8 @@ +NO +YES +NO +NO +NO +NO +NO +NO From ae7bdda803a07f36c99dc03382fc1fe8153a8f3a Mon Sep 17 00:00:00 2001 From: Ihnatsi Byshniou Date: Wed, 1 Nov 2023 22:40:29 +0100 Subject: [PATCH 2/5] =?UTF-8?q?Usu=C5=84=20'description.txt'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- description.txt | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 description.txt diff --git a/description.txt b/description.txt deleted file mode 100644 index 6ca4676..0000000 --- a/description.txt +++ /dev/null @@ -1,8 +0,0 @@ -Read a description of a deterministic finite-state automaton in the AT&T format -(without weights) from the file in the first argument. - -Read strings from the standard input. -If a string is accepted by the -automaton, write YES, otherwise- write NO. - -The program is invoked like this: ./run.py fsa_description.arg < test1.in > test1.out From 623685310397e657e783ee124ed9f475c122b206 Mon Sep 17 00:00:00 2001 From: Ihnatsi Byshniou Date: Wed, 1 Nov 2023 22:40:35 +0100 Subject: [PATCH 3/5] =?UTF-8?q?Usu=C5=84=20'fsa=5Fdescription.arg'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fsa_description.arg | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 fsa_description.arg diff --git a/fsa_description.arg b/fsa_description.arg deleted file mode 100644 index 3505b65..0000000 --- a/fsa_description.arg +++ /dev/null @@ -1,16 +0,0 @@ -0 1 x -1 2 y -2 3 z -0 4 y -0 4 z -1 4 x -1 4 z -2 4 x -2 4 y -3 4 x -3 4 y -3 4 z -4 4 x -4 4 y -4 4 z -3 From d027c0f9a29526eb0974b5f4b6bc7933ed165770 Mon Sep 17 00:00:00 2001 From: Ihnatsi Byshniou Date: Wed, 1 Nov 2023 22:40:40 +0100 Subject: [PATCH 4/5] =?UTF-8?q?Usu=C5=84=20'run.py'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run.py | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 run.py diff --git a/run.py b/run.py deleted file mode 100644 index d0829a5..0000000 --- a/run.py +++ /dev/null @@ -1,29 +0,0 @@ -import sys -def write_answer(answer): - with open('test1.out', 'a') as file: - file.write(answer+'\n') -def find_next_position(position, character): - with open('fsa_description.arg', 'r') as readed_used_table: - for row_used_table in readed_used_table: - line = row_used_table.strip().split('\t') - if position == line[0] and character == line[2]: - return True,line[1] -# used_table = sys.argv[1] -# input_file = sys.argv[2] -with open('test1.out', 'w') as readed_output_file: - with open('test1.in', 'r') as readed_input_file: - for row_input_file in readed_input_file: - result = False - next_position = None - position = '0' - for character in row_input_file: - if character =='\n': - if position=='3': - write_answer('YES') - break - else: - write_answer('NO') - break - result, next_position = find_next_position(position,character) - if result == True: - position = next_position \ No newline at end of file From de8d0b6a664f07bc9c4885c0c68c660c3ab7b7cf Mon Sep 17 00:00:00 2001 From: Ihnatsi Byshniou Date: Wed, 1 Nov 2023 22:40:45 +0100 Subject: [PATCH 5/5] =?UTF-8?q?Usu=C5=84=20'test1.exp'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test1.exp | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 test1.exp diff --git a/test1.exp b/test1.exp deleted file mode 100644 index ff99c7b..0000000 --- a/test1.exp +++ /dev/null @@ -1,9 +0,0 @@ -NO -YES -NO -NO -NO -NO -NO -NO -NO \ No newline at end of file