tasks 1-4

This commit is contained in:
wojtekgoralewski 2023-11-11 18:51:47 +01:00
parent 5305efe82e
commit a6ab6337cd
12 changed files with 284 additions and 0 deletions

View File

@ -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

43
TaskB01/run.py Normal file
View File

@ -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

14
TaskB01/test.out Normal file
View File

@ -0,0 +1,14 @@
YES
NO
YES
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO

View File

@ -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

43
TaskB02/run.py Normal file
View File

@ -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

14
TaskB02/test.out Normal file
View File

@ -0,0 +1,14 @@
NO
YES
NO
YES
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO

View File

@ -0,0 +1,8 @@
0 1 1
0 2 0
1 1 1
1 2 0
2 2 1
2 1 0
1
0

43
TaskB03/run.py Normal file
View File

@ -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

14
TaskB03/test.out Normal file
View File

@ -0,0 +1,14 @@
NO
NO
YES
YES
YES
NO
YES
NO
YES
NO
YES
YES
NO
YES

View File

@ -0,0 +1,7 @@
0 1 1
0 2 0
1 1 1
1 2 0
2 2 1
2 1 0
2

44
TaskB04/run.py Normal file
View File

@ -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

22
TaskB04/test.out Normal file
View File

@ -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