diff --git a/TaskB01/fsa_description.arg b/TaskB01/fsa_description.arg index e69de29..06e9756 100644 --- a/TaskB01/fsa_description.arg +++ b/TaskB01/fsa_description.arg @@ -0,0 +1,16 @@ +0 1 0 +0 2 1 +1 2 0 +1 3 1 +2 2 0 +2 2 1 +3 4 0 +3 5 1 +4 4 0 +4 6 1 +5 5 1 +5 4 0 +6 4 0 +6 5 1 +3 +6 \ No newline at end of file diff --git a/TaskB01/run.py b/TaskB01/run.py new file mode 100644 index 0000000..90c1700 --- /dev/null +++ b/TaskB01/run.py @@ -0,0 +1,43 @@ +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] + transisions[(state_from, symbol)] = state_to + 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)] + 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/TaskB01/test.out b/TaskB01/test.out new file mode 100644 index 0000000..484228a --- /dev/null +++ b/TaskB01/test.out @@ -0,0 +1,14 @@ +YES +NO +YES +NO +YES +NO +NO +YES +NO +NO +NO +NO +NO +NO diff --git a/TaskB02/fsa_description.arg b/TaskB02/fsa_description.arg new file mode 100644 index 0000000..c83762b --- /dev/null +++ b/TaskB02/fsa_description.arg @@ -0,0 +1,16 @@ +0 1 1 +0 2 0 +1 2 1 +1 3 0 +2 2 0 +2 2 1 +3 4 1 +3 5 0 +4 4 1 +4 6 0 +5 5 0 +5 4 1 +6 4 1 +6 5 0 +3 +6 \ No newline at end of file diff --git a/TaskB02/run.py b/TaskB02/run.py new file mode 100644 index 0000000..90c1700 --- /dev/null +++ b/TaskB02/run.py @@ -0,0 +1,43 @@ +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] + transisions[(state_from, symbol)] = state_to + 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)] + 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/TaskB02/test.out b/TaskB02/test.out new file mode 100644 index 0000000..939a1ca --- /dev/null +++ b/TaskB02/test.out @@ -0,0 +1,14 @@ +NO +YES +NO +YES +NO +YES +YES +NO +NO +NO +NO +NO +NO +NO diff --git a/TaskB03/fsa_description.arg b/TaskB03/fsa_description.arg new file mode 100644 index 0000000..918e306 --- /dev/null +++ b/TaskB03/fsa_description.arg @@ -0,0 +1,8 @@ +0 1 1 +0 2 0 +1 1 1 +1 2 0 +2 2 1 +2 1 0 +1 +0 diff --git a/TaskB03/run.py b/TaskB03/run.py new file mode 100644 index 0000000..90c1700 --- /dev/null +++ b/TaskB03/run.py @@ -0,0 +1,43 @@ +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] + transisions[(state_from, symbol)] = state_to + 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)] + 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/TaskB03/test.out b/TaskB03/test.out new file mode 100644 index 0000000..9a5f7bb --- /dev/null +++ b/TaskB03/test.out @@ -0,0 +1,14 @@ +NO +NO +YES +YES +YES +NO +YES +NO +YES +NO +YES +YES +NO +YES diff --git a/TaskB04/fsa_description.arg b/TaskB04/fsa_description.arg new file mode 100644 index 0000000..d08b3bd --- /dev/null +++ b/TaskB04/fsa_description.arg @@ -0,0 +1,7 @@ +0 1 1 +0 2 0 +1 1 1 +1 2 0 +2 2 1 +2 1 0 +2 diff --git a/TaskB04/run.py b/TaskB04/run.py new file mode 100644 index 0000000..e4b2fb9 --- /dev/null +++ b/TaskB04/run.py @@ -0,0 +1,44 @@ +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] + 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)] + 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/TaskB04/test.out b/TaskB04/test.out new file mode 100644 index 0000000..375544b --- /dev/null +++ b/TaskB04/test.out @@ -0,0 +1,22 @@ +['0', '1', '1'] +['0', '2', '0'] +['1', '1', '1'] +['1', '2', '0'] +['2', '2', '1'] +['2', '1', '0'] +['2'] +{(0, '1'): 1, (0, '0'): 2, (1, '1'): 1, (1, '0'): 2, (2, '1'): 2, (2, '0'): 1} +YES +YES +NO +NO +NO +YES +NO +YES +NO +YES +NO +NO +YES +NO