From 0099fab67f4ba664f1744a1500b532d4dd84d45f Mon Sep 17 00:00:00 2001 From: Wojtek Date: Sat, 25 Nov 2023 00:42:52 +0100 Subject: [PATCH] B06-B09 --- TaskB06/dodatkowy_test.in | 6 + TaskB06/dodatkowy_test.out | 6 + TaskB06/fsa_description.arg | 190 +++++++++++++++++++++++++++++++ TaskB06/run.py | 47 ++++++++ TaskB06/simple.out | 3 + TaskB07/dodatkowy_test.in | 4 + TaskB07/dodatkowy_test.out | 4 + TaskB07/fsa_description.arg | 217 ++++++++++++++++++++++++++++++++++++ TaskB07/run.py | 47 ++++++++ TaskB07/simple.out | 3 + TaskB08/dodatkowy_test.in | 4 + TaskB08/dodatkowy_test.out | 4 + TaskB08/fsa_description.arg | 190 +++++++++++++++++++++++++++++++ TaskB08/run.py | 47 ++++++++ TaskB08/simple.out | 3 + TaskB09/dodatkowy_test.in | 8 ++ TaskB09/dodatkowy_test.out | 8 ++ TaskB09/fsa_description.arg | 217 ++++++++++++++++++++++++++++++++++++ TaskB09/run.py | 47 ++++++++ TaskB09/simple.out | 3 + 20 files changed, 1058 insertions(+) create mode 100644 TaskB06/dodatkowy_test.in create mode 100644 TaskB06/dodatkowy_test.out create mode 100644 TaskB06/fsa_description.arg create mode 100644 TaskB06/run.py create mode 100644 TaskB06/simple.out create mode 100644 TaskB07/dodatkowy_test.in create mode 100644 TaskB07/dodatkowy_test.out create mode 100644 TaskB07/fsa_description.arg create mode 100644 TaskB07/run.py create mode 100644 TaskB07/simple.out create mode 100644 TaskB08/dodatkowy_test.in create mode 100644 TaskB08/dodatkowy_test.out create mode 100644 TaskB08/fsa_description.arg create mode 100644 TaskB08/run.py create mode 100644 TaskB08/simple.out create mode 100644 TaskB09/dodatkowy_test.in create mode 100644 TaskB09/dodatkowy_test.out create mode 100644 TaskB09/fsa_description.arg create mode 100644 TaskB09/run.py create mode 100644 TaskB09/simple.out diff --git a/TaskB06/dodatkowy_test.in b/TaskB06/dodatkowy_test.in new file mode 100644 index 0000000..0f9988e --- /dev/null +++ b/TaskB06/dodatkowy_test.in @@ -0,0 +1,6 @@ +hamlet +haaamlet hamlet +aaaaaaaaahhhhhamletttttttt +ham let + +haa let ha hamlet \ No newline at end of file diff --git a/TaskB06/dodatkowy_test.out b/TaskB06/dodatkowy_test.out new file mode 100644 index 0000000..d8b63f9 --- /dev/null +++ b/TaskB06/dodatkowy_test.out @@ -0,0 +1,6 @@ +YES +YES +YES +NO +NO +YES diff --git a/TaskB06/fsa_description.arg b/TaskB06/fsa_description.arg new file mode 100644 index 0000000..b485767 --- /dev/null +++ b/TaskB06/fsa_description.arg @@ -0,0 +1,190 @@ +0 0 a +0 0 b +0 0 c +0 0 d +0 0 e +0 0 f +0 0 g +0 1 h +0 0 i +0 0 j +0 0 k +0 0 l +0 0 m +0 0 n +0 0 o +0 0 p +0 0 q +0 0 r +0 0 s +0 0 t +0 0 u +0 0 v +0 0 w +0 0 x +0 0 y +0 0 z +0 0 '' +1 2 a +1 0 b +1 0 c +1 0 d +1 0 e +1 0 f +1 0 g +1 0 h +1 0 i +1 0 j +1 0 k +1 0 l +1 0 m +1 0 n +1 0 o +1 0 p +1 0 q +1 0 r +1 0 s +1 0 t +1 0 u +1 0 v +1 0 w +1 0 x +1 0 y +1 0 z +1 0 '' +2 0 a +2 0 b +2 0 c +2 0 d +2 0 e +2 0 f +2 0 g +2 0 h +2 0 i +2 0 j +2 0 k +2 0 l +2 3 m +2 0 n +2 0 o +2 0 p +2 0 q +2 0 r +2 0 s +2 0 t +2 0 u +2 0 v +2 0 w +2 0 x +2 0 y +2 0 z +2 0 '' +3 0 a +3 0 b +3 0 c +3 0 d +3 0 e +3 0 f +3 0 g +3 0 h +3 0 i +3 0 j +3 0 k +3 4 l +3 0 m +3 0 n +3 0 o +3 0 p +3 0 q +3 0 r +3 0 s +3 0 t +3 0 u +3 0 v +3 0 w +3 0 x +3 0 y +3 0 z +3 0 '' +4 0 a +4 0 b +4 0 c +4 0 d +4 5 e +4 0 f +4 0 g +4 0 h +4 0 i +4 0 j +4 0 k +4 0 l +4 0 m +4 0 n +4 0 o +4 0 p +4 0 q +4 0 r +4 0 s +4 0 t +4 0 u +4 0 v +4 0 w +4 0 x +4 0 y +4 0 z +4 0 '' +5 0 a +5 0 b +5 0 c +5 0 d +5 0 e +5 0 f +5 0 g +5 0 h +5 0 i +5 0 j +5 0 k +5 0 l +5 0 m +5 0 n +5 0 o +5 0 p +5 0 q +5 0 r +5 0 s +5 6 t +5 0 u +5 0 v +5 0 w +5 0 x +5 0 y +5 0 z +5 0 '' +6 6 a +6 6 b +6 6 c +6 6 d +6 6 e +6 6 f +6 6 g +6 6 h +6 6 i +6 6 j +6 6 k +6 6 l +6 6 m +6 6 n +6 6 o +6 6 p +6 6 q +6 6 r +6 6 s +6 6 t +6 6 u +6 6 v +6 6 w +6 6 x +6 6 y +6 6 z +6 6 '' +6 \ No newline at end of file diff --git a/TaskB06/run.py b/TaskB06/run.py new file mode 100644 index 0000000..389c398 --- /dev/null +++ b/TaskB06/run.py @@ -0,0 +1,47 @@ +import sys + +def read_aut(fsa_path): + with open(fsa_path, "r", encoding="utf8") as file: + transisions = {} + accepting_states = set() + for line in file: + parts = line.strip().split() + #print(parts) + if len(parts) == 1: + accepting_states.add(int(parts[0])) + #print(accepting_states) + if len(parts) == 3: + state_from = int(parts[0]) + state_to = int(parts[1]) + symbol = parts[2] + if symbol == "''": + symbol = ' ' + transisions[(state_from, symbol)] = state_to + #print(transisions) + return transisions, accepting_states + #print(transisions) + +def is_accepting(transitions, accepting_states, line): + current_state = 0 #zakładam, że zawsze stan początkowy to 0 dla uproszczenia + for symbol in line.strip(): + if (current_state, symbol) in transitions: + current_state = transitions[(current_state, symbol)] + #print(current_state) + else: + return "NO" + if current_state in accepting_states: + return "YES" + else: + return "NO" + + + +fsa_path = sys.argv[1] +transitions, accepting_states = read_aut(fsa_path) + +for line in sys.stdin: + result = is_accepting(transitions, accepting_states, line) + #sys.stdout.write(result + '\n') + print(result) + +#python run.py fsa_description.arg < test1.in > test1.out \ No newline at end of file diff --git a/TaskB06/simple.out b/TaskB06/simple.out new file mode 100644 index 0000000..5158019 --- /dev/null +++ b/TaskB06/simple.out @@ -0,0 +1,3 @@ +NO +YES +YES diff --git a/TaskB07/dodatkowy_test.in b/TaskB07/dodatkowy_test.in new file mode 100644 index 0000000..127243e --- /dev/null +++ b/TaskB07/dodatkowy_test.in @@ -0,0 +1,4 @@ +oph elia +opheelia + +ooooophelia \ No newline at end of file diff --git a/TaskB07/dodatkowy_test.out b/TaskB07/dodatkowy_test.out new file mode 100644 index 0000000..f09ac88 --- /dev/null +++ b/TaskB07/dodatkowy_test.out @@ -0,0 +1,4 @@ +NO +NO +NO +YES diff --git a/TaskB07/fsa_description.arg b/TaskB07/fsa_description.arg new file mode 100644 index 0000000..4a320f4 --- /dev/null +++ b/TaskB07/fsa_description.arg @@ -0,0 +1,217 @@ +0 0 a +0 0 b +0 0 c +0 0 d +0 0 e +0 0 f +0 0 g +0 0 h +0 0 i +0 0 j +0 0 k +0 0 l +0 0 m +0 0 n +0 1 o +0 0 p +0 0 q +0 0 r +0 0 s +0 0 t +0 0 u +0 0 v +0 0 w +0 0 x +0 0 y +0 0 z +0 0 '' +1 0 a +1 0 b +1 0 c +1 0 d +1 0 e +1 0 f +1 0 g +1 0 h +1 0 i +1 0 j +1 0 k +1 0 l +1 0 m +1 0 n +1 0 o +1 2 p +1 0 q +1 0 r +1 0 s +1 0 t +1 0 u +1 0 v +1 0 w +1 0 x +1 0 y +1 0 z +1 0 '' +2 0 a +2 0 b +2 0 c +2 0 d +2 0 e +2 0 f +2 0 g +2 3 h +2 0 i +2 0 j +2 0 k +2 0 l +2 0 m +2 0 n +2 0 o +2 0 p +2 0 q +2 0 r +2 0 s +2 0 t +2 0 u +2 0 v +2 0 w +2 0 x +2 0 y +2 0 z +2 0 '' +3 0 a +3 0 b +3 0 c +3 0 d +3 4 e +3 0 f +3 0 g +3 0 h +3 0 i +3 0 j +3 0 k +3 0 l +3 0 m +3 0 n +3 0 o +3 0 p +3 0 q +3 0 r +3 0 s +3 0 t +3 0 u +3 0 v +3 0 w +3 0 x +3 0 y +3 0 z +3 0 '' +4 0 a +4 0 b +4 0 c +4 0 d +4 0 e +4 0 f +4 0 g +4 0 h +4 0 i +4 0 j +4 0 k +4 5 l +4 0 m +4 0 n +4 0 o +4 0 p +4 0 q +4 0 r +4 0 s +4 0 t +4 0 u +4 0 v +4 0 w +4 0 x +4 0 y +4 0 z +4 0 '' +5 0 a +5 0 b +5 0 c +5 0 d +5 0 e +5 0 f +5 0 g +5 0 h +5 6 i +5 0 j +5 0 k +5 0 l +5 0 m +5 0 n +5 0 o +5 0 p +5 0 q +5 0 r +5 0 s +5 0 t +5 0 u +5 0 v +5 0 w +5 0 x +5 0 y +5 0 z +5 0 '' +6 7 a +6 0 b +6 0 c +6 0 d +6 0 e +6 0 f +6 0 g +6 0 h +6 0 i +6 0 j +6 0 k +6 0 l +6 0 m +6 0 n +6 0 o +6 0 p +6 0 q +6 0 r +6 0 s +6 0 t +6 0 u +6 0 v +6 0 w +6 0 x +6 0 y +6 0 z +6 0 '' +7 7 a +7 7 b +7 7 c +7 7 d +7 7 e +7 7 f +7 7 g +7 7 h +7 7 i +7 7 j +7 7 k +7 7 l +7 7 m +7 7 n +7 7 o +7 7 p +7 7 q +7 7 r +7 7 s +7 7 t +7 7 u +7 7 v +7 7 w +7 7 x +7 7 y +7 7 z +7 7 '' +7 \ No newline at end of file diff --git a/TaskB07/run.py b/TaskB07/run.py new file mode 100644 index 0000000..389c398 --- /dev/null +++ b/TaskB07/run.py @@ -0,0 +1,47 @@ +import sys + +def read_aut(fsa_path): + with open(fsa_path, "r", encoding="utf8") as file: + transisions = {} + accepting_states = set() + for line in file: + parts = line.strip().split() + #print(parts) + if len(parts) == 1: + accepting_states.add(int(parts[0])) + #print(accepting_states) + if len(parts) == 3: + state_from = int(parts[0]) + state_to = int(parts[1]) + symbol = parts[2] + if symbol == "''": + symbol = ' ' + transisions[(state_from, symbol)] = state_to + #print(transisions) + return transisions, accepting_states + #print(transisions) + +def is_accepting(transitions, accepting_states, line): + current_state = 0 #zakładam, że zawsze stan początkowy to 0 dla uproszczenia + for symbol in line.strip(): + if (current_state, symbol) in transitions: + current_state = transitions[(current_state, symbol)] + #print(current_state) + else: + return "NO" + if current_state in accepting_states: + return "YES" + else: + return "NO" + + + +fsa_path = sys.argv[1] +transitions, accepting_states = read_aut(fsa_path) + +for line in sys.stdin: + result = is_accepting(transitions, accepting_states, line) + #sys.stdout.write(result + '\n') + print(result) + +#python run.py fsa_description.arg < test1.in > test1.out \ No newline at end of file diff --git a/TaskB07/simple.out b/TaskB07/simple.out new file mode 100644 index 0000000..5158019 --- /dev/null +++ b/TaskB07/simple.out @@ -0,0 +1,3 @@ +NO +YES +YES diff --git a/TaskB08/dodatkowy_test.in b/TaskB08/dodatkowy_test.in new file mode 100644 index 0000000..eabe6af --- /dev/null +++ b/TaskB08/dodatkowy_test.in @@ -0,0 +1,4 @@ +juliet +juuuuliet juliet +ju liet + diff --git a/TaskB08/dodatkowy_test.out b/TaskB08/dodatkowy_test.out new file mode 100644 index 0000000..c322bb3 --- /dev/null +++ b/TaskB08/dodatkowy_test.out @@ -0,0 +1,4 @@ +YES +YES +NO +NO diff --git a/TaskB08/fsa_description.arg b/TaskB08/fsa_description.arg new file mode 100644 index 0000000..5376252 --- /dev/null +++ b/TaskB08/fsa_description.arg @@ -0,0 +1,190 @@ +0 0 a +0 0 b +0 0 c +0 0 d +0 0 e +0 0 f +0 0 g +0 0 h +0 0 i +0 1 j +0 0 k +0 0 l +0 0 m +0 0 n +0 0 o +0 0 p +0 0 q +0 0 r +0 0 s +0 0 t +0 0 u +0 0 v +0 0 w +0 0 x +0 0 y +0 0 z +0 0 '' +1 0 a +1 0 b +1 0 c +1 0 d +1 0 e +1 0 f +1 0 g +1 0 h +1 0 i +1 0 j +1 0 k +1 0 l +1 0 m +1 0 n +1 0 o +1 0 p +1 0 q +1 0 r +1 0 s +1 0 t +1 2 u +1 0 v +1 0 w +1 0 x +1 0 y +1 0 z +1 0 '' +2 0 a +2 0 b +2 0 c +2 0 d +2 0 e +2 0 f +2 0 g +2 0 h +2 0 i +2 0 j +2 0 k +2 3 l +2 0 m +2 0 n +2 0 o +2 0 p +2 0 q +2 0 r +2 0 s +2 0 t +2 0 u +2 0 v +2 0 w +2 0 x +2 0 y +2 0 z +2 0 '' +3 0 a +3 0 b +3 0 c +3 0 d +3 0 e +3 0 f +3 0 g +3 0 h +3 4 i +3 0 j +3 0 k +3 0 l +3 0 m +3 0 n +3 0 o +3 0 p +3 0 q +3 0 r +3 0 s +3 0 t +3 0 u +3 0 v +3 0 w +3 0 x +3 0 y +3 0 z +3 0 '' +4 0 a +4 0 b +4 0 c +4 0 d +4 5 e +4 0 f +4 0 g +4 0 h +4 0 i +4 0 j +4 0 k +4 0 l +4 0 m +4 0 n +4 0 o +4 0 p +4 0 q +4 0 r +4 0 s +4 0 t +4 0 u +4 0 v +4 0 w +4 0 x +4 0 y +4 0 z +4 0 '' +5 0 a +5 0 b +5 0 c +5 0 d +5 0 e +5 0 f +5 0 g +5 0 h +5 0 i +5 0 j +5 0 k +5 0 l +5 0 m +5 0 n +5 0 o +5 0 p +5 0 q +5 0 r +5 0 s +5 6 t +5 0 u +5 0 v +5 0 w +5 0 x +5 0 y +5 0 z +5 0 '' +6 6 a +6 6 b +6 6 c +6 6 d +6 6 e +6 6 f +6 6 g +6 6 h +6 6 i +6 6 j +6 6 k +6 6 l +6 6 m +6 6 n +6 6 o +6 6 p +6 6 q +6 6 r +6 6 s +6 6 t +6 6 u +6 6 v +6 6 w +6 6 x +6 6 y +6 6 z +6 6 '' +6 \ No newline at end of file diff --git a/TaskB08/run.py b/TaskB08/run.py new file mode 100644 index 0000000..389c398 --- /dev/null +++ b/TaskB08/run.py @@ -0,0 +1,47 @@ +import sys + +def read_aut(fsa_path): + with open(fsa_path, "r", encoding="utf8") as file: + transisions = {} + accepting_states = set() + for line in file: + parts = line.strip().split() + #print(parts) + if len(parts) == 1: + accepting_states.add(int(parts[0])) + #print(accepting_states) + if len(parts) == 3: + state_from = int(parts[0]) + state_to = int(parts[1]) + symbol = parts[2] + if symbol == "''": + symbol = ' ' + transisions[(state_from, symbol)] = state_to + #print(transisions) + return transisions, accepting_states + #print(transisions) + +def is_accepting(transitions, accepting_states, line): + current_state = 0 #zakładam, że zawsze stan początkowy to 0 dla uproszczenia + for symbol in line.strip(): + if (current_state, symbol) in transitions: + current_state = transitions[(current_state, symbol)] + #print(current_state) + else: + return "NO" + if current_state in accepting_states: + return "YES" + else: + return "NO" + + + +fsa_path = sys.argv[1] +transitions, accepting_states = read_aut(fsa_path) + +for line in sys.stdin: + result = is_accepting(transitions, accepting_states, line) + #sys.stdout.write(result + '\n') + print(result) + +#python run.py fsa_description.arg < test1.in > test1.out \ No newline at end of file diff --git a/TaskB08/simple.out b/TaskB08/simple.out new file mode 100644 index 0000000..5158019 --- /dev/null +++ b/TaskB08/simple.out @@ -0,0 +1,3 @@ +NO +YES +YES diff --git a/TaskB09/dodatkowy_test.in b/TaskB09/dodatkowy_test.in new file mode 100644 index 0000000..c65602f --- /dev/null +++ b/TaskB09/dodatkowy_test.in @@ -0,0 +1,8 @@ +macbeth +hdusahdsuia dsadsa dsa d macbeth +dsadsamacbethdsadsa +a macbeth + +mac beth + +m a c beth diff --git a/TaskB09/dodatkowy_test.out b/TaskB09/dodatkowy_test.out new file mode 100644 index 0000000..a699e04 --- /dev/null +++ b/TaskB09/dodatkowy_test.out @@ -0,0 +1,8 @@ +YES +YES +YES +YES +NO +NO +NO +NO diff --git a/TaskB09/fsa_description.arg b/TaskB09/fsa_description.arg new file mode 100644 index 0000000..bdec15a --- /dev/null +++ b/TaskB09/fsa_description.arg @@ -0,0 +1,217 @@ +0 0 a +0 0 b +0 0 c +0 0 d +0 0 e +0 0 f +0 0 g +0 0 h +0 0 i +0 0 j +0 0 k +0 0 l +0 1 m +0 0 n +0 0 o +0 0 p +0 0 q +0 0 r +0 0 s +0 0 t +0 0 u +0 0 v +0 0 w +0 0 x +0 0 y +0 0 z +0 0 '' +1 2 a +1 0 b +1 0 c +1 0 d +1 0 e +1 0 f +1 0 g +1 0 h +1 0 i +1 0 j +1 0 k +1 0 l +1 0 m +1 0 n +1 0 o +1 0 p +1 0 q +1 0 r +1 0 s +1 0 t +1 0 u +1 0 v +1 0 w +1 0 x +1 0 y +1 0 z +1 0 '' +2 0 a +2 0 b +2 3 c +2 0 d +2 0 e +2 0 f +2 0 g +2 0 h +2 0 i +2 0 j +2 0 k +2 0 l +2 0 m +2 0 n +2 0 o +2 0 p +2 0 q +2 0 r +2 0 s +2 0 t +2 0 u +2 0 v +2 0 w +2 0 x +2 0 y +2 0 z +2 0 '' +3 0 a +3 4 b +3 0 c +3 0 d +3 0 e +3 0 f +3 0 g +3 0 h +3 0 i +3 0 j +3 0 k +3 0 l +3 0 m +3 0 n +3 0 o +3 0 p +3 0 q +3 0 r +3 0 s +3 0 t +3 0 u +3 0 v +3 0 w +3 0 x +3 0 y +3 0 z +3 0 '' +4 0 a +4 0 b +4 0 c +4 0 d +4 5 e +4 0 f +4 0 g +4 0 h +4 0 i +4 0 j +4 0 k +4 0 l +4 0 m +4 0 n +4 0 o +4 0 p +4 0 q +4 0 r +4 0 s +4 0 t +4 0 u +4 0 v +4 0 w +4 0 x +4 0 y +4 0 z +4 0 '' +5 0 a +5 0 b +5 0 c +5 0 d +5 0 e +5 0 f +5 0 g +5 0 h +5 0 i +5 0 j +5 0 k +5 0 l +5 0 m +5 0 n +5 0 o +5 0 p +5 0 q +5 0 r +5 0 s +5 6 t +5 0 u +5 0 v +5 0 w +5 0 x +5 0 y +5 0 z +5 0 '' +6 0 a +6 0 b +6 0 c +6 0 d +6 0 e +6 0 f +6 0 g +6 7 h +6 0 i +6 0 j +6 0 k +6 0 l +6 0 m +6 0 n +6 0 o +6 0 p +6 0 q +6 0 r +6 0 s +6 0 t +6 0 u +6 0 v +6 0 w +6 0 x +6 0 y +6 0 z +6 0 '' +7 7 a +7 7 b +7 7 c +7 7 d +7 7 e +7 7 f +7 7 g +7 7 h +7 7 i +7 7 j +7 7 k +7 7 l +7 7 m +7 7 n +7 7 o +7 7 p +7 7 q +7 7 r +7 7 s +7 7 t +7 7 u +7 7 v +7 7 w +7 7 x +7 7 y +7 7 z +7 7 '' +7 \ No newline at end of file diff --git a/TaskB09/run.py b/TaskB09/run.py new file mode 100644 index 0000000..389c398 --- /dev/null +++ b/TaskB09/run.py @@ -0,0 +1,47 @@ +import sys + +def read_aut(fsa_path): + with open(fsa_path, "r", encoding="utf8") as file: + transisions = {} + accepting_states = set() + for line in file: + parts = line.strip().split() + #print(parts) + if len(parts) == 1: + accepting_states.add(int(parts[0])) + #print(accepting_states) + if len(parts) == 3: + state_from = int(parts[0]) + state_to = int(parts[1]) + symbol = parts[2] + if symbol == "''": + symbol = ' ' + transisions[(state_from, symbol)] = state_to + #print(transisions) + return transisions, accepting_states + #print(transisions) + +def is_accepting(transitions, accepting_states, line): + current_state = 0 #zakładam, że zawsze stan początkowy to 0 dla uproszczenia + for symbol in line.strip(): + if (current_state, symbol) in transitions: + current_state = transitions[(current_state, symbol)] + #print(current_state) + else: + return "NO" + if current_state in accepting_states: + return "YES" + else: + return "NO" + + + +fsa_path = sys.argv[1] +transitions, accepting_states = read_aut(fsa_path) + +for line in sys.stdin: + result = is_accepting(transitions, accepting_states, line) + #sys.stdout.write(result + '\n') + print(result) + +#python run.py fsa_description.arg < test1.in > test1.out \ No newline at end of file diff --git a/TaskB09/simple.out b/TaskB09/simple.out new file mode 100644 index 0000000..5158019 --- /dev/null +++ b/TaskB09/simple.out @@ -0,0 +1,3 @@ +NO +YES +YES